From 8023a5f98673ac65af45fbc955fae276d1171740 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Tue, 17 Oct 2023 11:06:32 +0200 Subject: [PATCH] fix: Make Timers sheet grow on height change --- lib/widgets/ModalSheetContent.dart | 4 +- lib/widgets/TimerWidget.dart | 3 + lib/widgets/TimerWidgetSheet.dart | 228 +++++++++++++++-------------- 3 files changed, 120 insertions(+), 115 deletions(-) diff --git a/lib/widgets/ModalSheetContent.dart b/lib/widgets/ModalSheetContent.dart index 9bb8be99..08525f57 100644 --- a/lib/widgets/ModalSheetContent.dart +++ b/lib/widgets/ModalSheetContent.dart @@ -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; @@ -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), diff --git a/lib/widgets/TimerWidget.dart b/lib/widgets/TimerWidget.dart index 97c3d470..be227823 100644 --- a/lib/widgets/TimerWidget.dart +++ b/lib/widgets/TimerWidget.dart @@ -65,12 +65,14 @@ class TimerController extends ChangeNotifier { class TimerWidget extends StatefulWidget { final TimerController? controller; + final ScrollController? scrollController; final List timers; final bool allowEdit; final ScrollPhysics? physics; const TimerWidget({ this.controller, + this.scrollController, this.timers = const [], this.allowEdit = true, this.physics, @@ -126,6 +128,7 @@ class _TimerWidgetState extends State { Widget build(BuildContext context) { return ListView.builder( shrinkWrap: true, + controller: widget.scrollController, physics: widget.physics, itemCount: _controller.timers.length, itemBuilder: (_, index) { diff --git a/lib/widgets/TimerWidgetSheet.dart b/lib/widgets/TimerWidgetSheet.dart index 2accbe4d..78396667 100644 --- a/lib/widgets/TimerWidgetSheet.dart +++ b/lib/widgets/TimerWidgetSheet.dart @@ -54,138 +54,140 @@ class _TimerWidgetSheetState extends State { 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: [ - PlatformPopup( - type: PlatformPopupType.longPress, - items: List>.from( - WEEKDAY_TIMERS.entries.map( - (entry) => PlatformPopupMenuItem( - label: Text(entry.value["name"] as String), - onPressed: () { - widget.controller.clear(); - - final timers = - entry.value["timers"] as List; - widget.controller.addAll(timers); - - Navigator.pop(context); - }, + const SizedBox(height: MEDIUM_SPACE), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + PlatformPopup( + type: PlatformPopupType.longPress, + items: List>.from( + WEEKDAY_TIMERS.entries.map( + (entry) => PlatformPopupMenuItem( + label: Text(entry.value["name"] as String), + onPressed: () { + widget.controller.clear(); + + final timers = + entry.value["timers"] as List; + 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!, - ), - ); - } - }, - ), - ], - ), - ], + ], + ), + ], + ), ), ), );