From 1dbab57edd9c34aef1bfca8065ef3ea0847b76df Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Fri, 26 Jul 2024 14:33:58 -0400 Subject: [PATCH] Make focus mode duration completely configurable up to 24 hours --- lib/controls/focus_mode_menu_item.dart | 94 ++++++++++++++++++++++---- pubspec.lock | 8 +++ pubspec.yaml | 1 + 3 files changed, 88 insertions(+), 15 deletions(-) diff --git a/lib/controls/focus_mode_menu_item.dart b/lib/controls/focus_mode_menu_item.dart index fe0077f..3a3b9f5 100644 --- a/lib/controls/focus_mode_menu_item.dart +++ b/lib/controls/focus_mode_menu_item.dart @@ -1,19 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; -import 'package:relatica/globals.dart'; +import 'package:wheel_chooser/wheel_chooser.dart'; import '../models/focus_mode_data.dart'; import '../riverpod_controllers/focus_mode.dart'; import '../routes.dart'; - -final _options = { - '1 hour': const Duration(hours: 1), - '30 minutes': const Duration(minutes: 30), - '15 minutes': const Duration(minutes: 15), - '5 minutes': const Duration(minutes: 5), - '1 minute': const Duration(minutes: 1), -}; +import 'padding.dart'; class FocusModeMenuItem extends ConsumerWidget { const FocusModeMenuItem({super.key}); @@ -32,19 +25,90 @@ class FocusModeMenuItem extends ConsumerWidget { context.pop(); context.push(ScreenPaths.focusModeDisable); } else { - final result = await showChooseOptions(context, - 'How long would you like to focus?', _options.keys.toList()); - if (result == null) { + final duration = await _chooseDuration(context); + if (duration == null) { return; } - final disableTime = DateTime.now().add(_options[result]!); + final disableTime = DateTime.now().add(duration); final update = FocusModeData(true, disableTime: disableTime); ref.read(focusModeProvider.notifier).setMode(update); - context.pop(); - context.go(ScreenPaths.timelines); + if (context.mounted) { + context.pop(); + context.go(ScreenPaths.timelines); + } } }, ), ); } } + +Future _chooseDuration( + BuildContext context, +) { + var hours = 0; + var minutes = 30; + + return showDialog( + context: context, + barrierDismissible: false, + builder: (BuildContext context) { + return AlertDialog( + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'Choose Focus Duration', + style: Theme.of(context) + .textTheme + .bodyLarge! + .copyWith(fontWeight: FontWeight.bold), + ), + const VerticalPadding(), + SizedBox( + height: 100, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Flexible( + child: WheelChooser.integer( + initValue: hours, + onValueChanged: (v) => hours = v, + maxValue: 24, + minValue: 0, + unSelectTextStyle: const TextStyle(color: Colors.grey), + ), + ), + const Text('hours'), + Flexible( + child: WheelChooser.integer( + initValue: minutes, + onValueChanged: (v) => minutes = v, + maxValue: 59, + minValue: 0, + unSelectTextStyle: const TextStyle(color: Colors.grey), + ), + ), + const Text('minutes'), + ], + ), + ) + ], + ), + actions: [ + ElevatedButton( + child: const Text('Select'), + onPressed: () { + Navigator.pop( + context, + Duration( + hours: hours, + minutes: minutes, + ), + ); // showDialog() returns true + }, + ) + ]); + }, + ); +} diff --git a/pubspec.lock b/pubspec.lock index 02e5ee4..20ea19b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1685,6 +1685,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" + wheel_chooser: + dependency: "direct main" + description: + name: wheel_chooser + sha256: "3fee36f081f321c58a0b7b4afcdd92599f2ca520b3a1420084774e6b19cca1d8" + url: "https://pub.dev" + source: hosted + version: "1.1.2" win32: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 5d81f24..d277726 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -58,6 +58,7 @@ dependencies: url_launcher: ^6.3.0 uuid: ^4.4.2 video_player: ^2.9.1 + wheel_chooser: ^1.1.2 dev_dependencies: flutter_test: