Skip to content

Commit

Permalink
bug: fixed custom time picker
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazahir26 committed Jun 26, 2024
1 parent d544847 commit 88fdc1c
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 66 deletions.
131 changes: 74 additions & 57 deletions lib/components/create_task_bottom_sheet.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:duration_picker/duration_picker.dart';
import 'package:flutter/material.dart';
import 'package:koduko/components/name_page_bottom_sheet.dart';
import 'package:koduko/models/task.dart';
Expand Down Expand Up @@ -25,7 +26,7 @@ class _CreateTaskBottomSheetState extends State<CreateTaskBottomSheet> {
"20 mins": Duration(minutes: 20),
"25 mins": Duration(minutes: 25),
"30 mins": Duration(minutes: 30),
"Custom": Duration(minutes: 30),
"Custom": Duration(minutes: 5),
};
static const colorList = [
Colors.blue,
Expand All @@ -37,7 +38,7 @@ class _CreateTaskBottomSheetState extends State<CreateTaskBottomSheet> {
Colors.red,
];

Duration customTime = const Duration(seconds: 0);
Duration customTime = const Duration(minutes: 5);
String? _value;
int? _selectedColor;
int pageIndex = 0;
Expand Down Expand Up @@ -97,70 +98,86 @@ class _CreateTaskBottomSheetState extends State<CreateTaskBottomSheet> {

void onChangeChip(bool selected, int index, BuildContext context) async {
if (chipList.keys.toList()[index] == 'Custom') {
final r = await onCustomDurationSelect(context);
if (!r) {
final r = await showDurationPicker(
context: context,
initialTime: _value != null
? _value == 'Custom'
? customTime
: chipList[_value] ?? customTime
: customTime,
baseUnit: BaseUnit.second,
lowerBound: const Duration(seconds: 15),
upperBound: const Duration(hours: 1),
);

if (r == null) {
return;
}
setState(() {
customTime = r;
_value = 'Custom';
});
validateDuration();
return;
}
setState(() {
_value = selected ? chipList.keys.toList()[index] : null;
});
validateDuration();
}

Future<bool> onCustomDurationSelect(BuildContext context) async {
const result = null;
// final result = await Picker(
// adapter: NumberPickerAdapter(data: <NumberPickerColumn>[
// const NumberPickerColumn(begin: 0, end: 30, suffix: Text(' minutes')),
// const NumberPickerColumn(begin: 5, end: 60, suffix: Text(' seconds')),
// ]),
// backgroundColor: Theme.of(context).colorScheme.surface,
// onBuilderItem: (context, text, child, selected, col, index) {
// String t = text == null
// ? ''
// : col == 0
// ? '$text min'
// : '$text sec';
// return Center(
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// children: [
// Text(
// t,
// style: selected
// ? Theme.of(context)
// .textTheme
// .titleLarge!
// .apply(color: Theme.of(context).colorScheme.primary)
// : Theme.of(context).textTheme.titleMedium,
// )
// ],
// ),
// );
// },
// looping: true,
// magnification: 1.1,
// itemExtent: 50,
// hideHeader: true,
// confirmText: 'Select',
// title: const Text('Select duration'),
// onConfirm: (Picker picker, List<int> value) {
// Duration duration = Duration(
// minutes: picker.getSelectedValues()[0],
// seconds: picker.getSelectedValues()[1]);
// setState(() {
// customTime = duration;
// });
// validateDuration();
// },
// ).showDialog(context);
if (result == null) {
return false;
} else {
return true;
}
}
// Future<bool> onCustomDurationSelect(BuildContext context) async {
// final result = await Picker(
// adapter: NumberPickerAdapter(data: <NumberPickerColumn>[
// const NumberPickerColumn(begin: 0, end: 30, suffix: Text(' minutes')),
// const NumberPickerColumn(begin: 5, end: 60, suffix: Text(' seconds')),
// ]),
// backgroundColor: Theme.of(context).colorScheme.surface,
// onBuilderItem: (context, text, child, selected, col, index) {
// String t = text == null
// ? ''
// : col == 0
// ? '$text min'
// : '$text sec';
// return Center(
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// children: [
// Text(
// t,
// style: selected
// ? Theme.of(context)
// .textTheme
// .titleLarge!
// .apply(color: Theme.of(context).colorScheme.primary)
// : Theme.of(context).textTheme.titleMedium,
// )
// ],
// ),
// );
// },
// looping: true,
// magnification: 1.1,
// itemExtent: 50,
// hideHeader: true,
// confirmText: 'Select',
// title: const Text('Select duration'),
// onConfirm: (Picker picker, List<int> value) {
// Duration duration = Duration(
// minutes: picker.getSelectedValues()[0],
// seconds: picker.getSelectedValues()[1]);
// setState(() {
// customTime = duration;
// });
// validateDuration();
// },
// ).showDialog(context);
// if (result == null) {
// return false;
// } else {
// return true;
// }
// }

void onChangeColor(int index) {
setState(() {
Expand Down
24 changes: 16 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.10"
duration_picker:
dependency: "direct main"
description:
name: duration_picker
sha256: e505a749c93f3218aa4194d339e5d5480d927df23a81f075b5282511f6ac11ab
url: "https://pub.dev"
source: hosted
version: "1.2.0"
dynamic_color:
dependency: "direct main"
description:
Expand Down Expand Up @@ -310,14 +318,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.0"
flutter_picker:
dependency: "direct main"
description:
name: flutter_picker
sha256: "2f94c6eefba8697b07e3cd008b75f06b4ba7053cb26d23ae0fcd5932b7dc75af"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
flutter_slidable:
dependency: "direct main"
description:
Expand Down Expand Up @@ -488,6 +488,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.0"
logger:
dependency: "direct main"
description:
name: logger
sha256: af05cc8714f356fd1f3888fb6741cbe9fbe25cdb6eedbab80e1a6db21047d4a4
url: "https://pub.dev"
source: hosted
version: "2.3.0"
logging:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ dependencies:
timezone: ^0.9.0
flutter_native_timezone: ^2.0.0
url_launcher: ^6.1.5
flutter_picker: ^2.0.5
dynamic_color: ^1.6.9
duration_picker: ^1.2.0
logger: ^2.3.0

# flutter_icons:
# android: "launcher_icon"
Expand Down

0 comments on commit 88fdc1c

Please sign in to comment.