Skip to content

Commit

Permalink
fix: Make Timers sheet grow on height change
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Oct 17, 2023
1 parent b83bfb6 commit 8023a5f
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 115 deletions.
4 changes: 2 additions & 2 deletions lib/widgets/ModalSheetContent.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:locus/services/settings_service/index.dart';
import 'package:locus/utils/theme.dart';
import 'package:provider/provider.dart';

import '../constants/spacing.dart';
import 'package:locus/services/settings_service/index.dart';

class ModalSheetContent extends StatelessWidget {
final String title;
Expand Down Expand Up @@ -61,7 +61,7 @@ class ModalSheetContent extends StatelessWidget {
style: getCaptionTextStyle(context),
),
],
const SizedBox(height: LARGE_SPACE),
if (isMaterial(context)) const SizedBox(height: LARGE_SPACE),
...children,
if (submitLabel != null) ...[
const SizedBox(height: LARGE_SPACE),
Expand Down
3 changes: 3 additions & 0 deletions lib/widgets/TimerWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ class TimerController extends ChangeNotifier {

class TimerWidget extends StatefulWidget {
final TimerController? controller;
final ScrollController? scrollController;
final List<TaskRuntimeTimer> timers;
final bool allowEdit;
final ScrollPhysics? physics;

const TimerWidget({
this.controller,
this.scrollController,
this.timers = const [],
this.allowEdit = true,
this.physics,
Expand Down Expand Up @@ -126,6 +128,7 @@ class _TimerWidgetState extends State<TimerWidget> {
Widget build(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
controller: widget.scrollController,
physics: widget.physics,
itemCount: _controller.timers.length,
itemBuilder: (_, index) {
Expand Down
228 changes: 115 additions & 113 deletions lib/widgets/TimerWidgetSheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,138 +54,140 @@ class _TimerWidgetSheetState extends State<TimerWidgetSheet> {
return DraggableScrollableSheet(
initialChildSize: 0.6,
minChildSize: 0.6,
maxChildSize: 0.6,
maxChildSize: 1,
expand: false,
builder: (_, __) => ModalSheet(
child: ModalSheetContent(
title: l10n.detailsTimersLabel,
submitLabel: l10n.closePositiveSheetAction,
onSubmit: (widget.controller.timers.isEmpty && !widget.allowEmpty)
? null
: () {
Navigator.of(context).pop(widget.controller.timers);
},
children: [
if (widget.controller.timers.isNotEmpty) ...[
Expanded(
child: TimerWidget(
builder: (context, controller) => ModalSheet(
child: SingleChildScrollView(
controller: controller,
child: ModalSheetContent(
title: l10n.detailsTimersLabel,
submitLabel: l10n.closePositiveSheetAction,
onSubmit: (widget.controller.timers.isEmpty && !widget.allowEmpty)
? null
: () {
Navigator.of(context).pop(widget.controller.timers);
},
children: [
if (widget.controller.timers.isNotEmpty) ...[
TimerWidget(
controller: widget.controller,
physics: const NeverScrollableScrollPhysics(),
),
),
const SizedBox(height: SMALL_SPACE),
if (findNextStartDate(widget.controller.timers) == null)
Text(l10n.timer_executionStartsImmediately)
else
Text(l10n.timer_nextExecution(
findNextStartDate(widget.controller.timers)!)),
if (widget.controller.timers
.any((timer) => timer.isInfinite())) ...[
const SizedBox(height: SMALL_SPACE),
WarningText(l10n.timer_runsInfiniteMessage),
if (findNextStartDate(widget.controller.timers) == null)
Text(l10n.timer_executionStartsImmediately)
else
Text(l10n.timer_nextExecution(
findNextStartDate(widget.controller.timers)!)),
if (widget.controller.timers
.any((timer) => timer.isInfinite())) ...[
const SizedBox(height: SMALL_SPACE),
WarningText(l10n.timer_runsInfiniteMessage),
],
],
],
const SizedBox(height: MEDIUM_SPACE),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
PlatformPopup<String>(
type: PlatformPopupType.longPress,
items: List<PlatformPopupMenuItem<String>>.from(
WEEKDAY_TIMERS.entries.map(
(entry) => PlatformPopupMenuItem<String>(
label: Text(entry.value["name"] as String),
onPressed: () {
widget.controller.clear();

final timers =
entry.value["timers"] as List<WeekdayTimer>;
widget.controller.addAll(timers);

Navigator.pop(context);
},
const SizedBox(height: MEDIUM_SPACE),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
PlatformPopup<String>(
type: PlatformPopupType.longPress,
items: List<PlatformPopupMenuItem<String>>.from(
WEEKDAY_TIMERS.entries.map(
(entry) => PlatformPopupMenuItem<String>(
label: Text(entry.value["name"] as String),
onPressed: () {
widget.controller.clear();

final timers =
entry.value["timers"] as List<WeekdayTimer>;
widget.controller.addAll(timers);

Navigator.pop(context);
},
),
),
),
child: PlatformTextButton(
child: Text(l10n.timer_addWeekday),
material: (_, __) => MaterialTextButtonData(
icon: const Icon(Icons.date_range_rounded),
),
onPressed: () async {
final data = await showPlatformDialog(
context: context,
builder: (_) => const WeekdaySelection(),
);

if (!mounted) {
return;
}

if (data != null) {
widget.controller.add(
WeekdayTimer(
day: data["weekday"] as int,
startTime: data["startTime"] as TimeOfDay,
endTime: data["endTime"] as TimeOfDay,
),
);
}
},
),
),
child: PlatformTextButton(
child: Text(l10n.timer_addWeekday),
PlatformTextButton(
child: Text(l10n.timer_addDuration),
material: (_, __) => MaterialTextButtonData(
icon: const Icon(Icons.date_range_rounded),
icon: const Icon(Icons.timelapse_rounded),
),
onPressed: () async {
final data = await showPlatformDialog(
context: context,
builder: (_) => const WeekdaySelection(),
);

if (!mounted) {
return;
Duration? duration;

if (isCupertino(context)) {
await showCupertinoModalPopup(
context: context,
builder: (context) => Container(
height: 300,
padding: const EdgeInsets.only(top: 6.0),
margin: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
color: CupertinoColors.systemBackground
.resolveFrom(context),
child: SafeArea(
top: false,
child: CupertinoTimerPicker(
initialTimerDuration: Duration.zero,
minuteInterval: 5,
onTimerDurationChanged: (value) {
duration = value;
},
mode: CupertinoTimerPickerMode.hm,
),
),
),
);
} else {
duration = await showDurationPicker(
context: context,
initialTime: Duration.zero,
snapToMins: 15.0,
);
}

if (data != null) {
if (duration != null && duration!.inSeconds > 0) {
widget.controller.add(
WeekdayTimer(
day: data["weekday"] as int,
startTime: data["startTime"] as TimeOfDay,
endTime: data["endTime"] as TimeOfDay,
DurationTimer(
duration: duration!,
),
);
}
},
),
),
PlatformTextButton(
child: Text(l10n.timer_addDuration),
material: (_, __) => MaterialTextButtonData(
icon: const Icon(Icons.timelapse_rounded),
),
onPressed: () async {
Duration? duration;

if (isCupertino(context)) {
await showCupertinoModalPopup(
context: context,
builder: (context) => Container(
height: 300,
padding: const EdgeInsets.only(top: 6.0),
margin: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
color: CupertinoColors.systemBackground
.resolveFrom(context),
child: SafeArea(
top: false,
child: CupertinoTimerPicker(
initialTimerDuration: Duration.zero,
minuteInterval: 5,
onTimerDurationChanged: (value) {
duration = value;
},
mode: CupertinoTimerPickerMode.hm,
),
),
),
);
} else {
duration = await showDurationPicker(
context: context,
initialTime: Duration.zero,
snapToMins: 15.0,
);
}

if (duration != null && duration!.inSeconds > 0) {
widget.controller.add(
DurationTimer(
duration: duration!,
),
);
}
},
),
],
),
],
],
),
],
),
),
),
);
Expand Down

0 comments on commit 8023a5f

Please sign in to comment.