Skip to content

Commit 43dedab

Browse files
Customise undo duration (#450)
* created customise undo duration ui * created duration controller and the inputscroller * add: added customisable undo duration
1 parent dd0d97e commit 43dedab

File tree

3 files changed

+153
-3
lines changed

3 files changed

+153
-3
lines changed

lib/app/modules/home/controllers/home_controller.dart

+7-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Pair<T, U> {
2525
}
2626

2727
class HomeController extends GetxController {
28+
2829
MethodChannel alarmChannel = const MethodChannel('ulticlock');
2930
Stream<QuerySnapshot>? firestoreStreamAlarms;
3031
Stream<QuerySnapshot>? sharedAlarmsStream;
@@ -61,6 +62,9 @@ class HomeController extends GetxController {
6162

6263
Set<Pair<dynamic, bool>> selectedAlarmSet = {};
6364

65+
final RxInt duration = 3.obs;
66+
final RxDouble selecteddurationDouble = 0.0.obs;
67+
6468
ThemeController themeController = Get.find<ThemeController>();
6569

6670
loginWithGoogle() async {
@@ -534,9 +538,9 @@ class HomeController extends GetxController {
534538
}
535539

536540
Get.snackbar(
537-
'Alarm deleted'.tr,
538-
'The alarm has been deleted'.tr,
539-
duration: const Duration(seconds: 4),
541+
'Alarm deleted',
542+
'The alarm has been deleted.',
543+
duration: Duration(seconds: duration.toInt()),
540544
snackPosition: SnackPosition.BOTTOM,
541545
margin: const EdgeInsets.symmetric(
542546
horizontal: 10,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
2+
import 'package:flutter/material.dart';
3+
import 'package:get/get.dart';
4+
import 'package:get/get_core/src/get_main.dart';
5+
import 'package:ultimate_alarm_clock/app/modules/home/controllers/home_controller.dart';
6+
7+
import '../../../utils/constants.dart';
8+
import '../../../utils/utils.dart';
9+
import '../controllers/theme_controller.dart';
10+
import 'package:ultimate_alarm_clock/app/modules/settings/controllers/settings_controller.dart';
11+
12+
class CustomizeUndoDuration extends StatelessWidget{
13+
HomeController homeController = Get.find<HomeController>();
14+
CustomizeUndoDuration({
15+
super.key ,
16+
required this.themeController,
17+
required this.height,
18+
required this.width,
19+
});
20+
final ThemeController themeController;
21+
final double width;
22+
final double height;
23+
24+
@override
25+
Widget build(BuildContext context) {
26+
int duration;
27+
return InkWell(
28+
onTap: () {
29+
Utils.hapticFeedback();
30+
duration = homeController.duration.value;
31+
Get.defaultDialog(
32+
onWillPop: () async {
33+
Get.back();
34+
// Resetting the value to its initial state
35+
homeController.duration.value = duration;
36+
return true;
37+
},
38+
titlePadding: const EdgeInsets.symmetric(vertical: 20, horizontal: 5),
39+
backgroundColor: themeController.isLightMode.value
40+
? kLightSecondaryBackgroundColor
41+
: ksecondaryBackgroundColor,
42+
title: 'Customize Undo Duration'.tr,
43+
titleStyle: Theme.of(context).textTheme.displaySmall,
44+
content: Obx(
45+
() => Column(
46+
children: [
47+
Text(
48+
'${homeController.duration.value} seconds'.tr,
49+
style: Theme.of(context).textTheme.displaySmall,
50+
),
51+
Slider(
52+
value: homeController.selecteddurationDouble.value,
53+
onChanged: (double value) {
54+
homeController.selecteddurationDouble.value = value;
55+
homeController.duration.value = value.toInt();
56+
57+
},
58+
min: 0.0,
59+
max: 20.0,
60+
divisions: 20,
61+
label: homeController.duration.value.toString(),
62+
),
63+
// Replace the volMin Slider with RangeSlider
64+
65+
ElevatedButton(
66+
onPressed: () {
67+
Get.back();
68+
},
69+
style: ElevatedButton.styleFrom(
70+
backgroundColor: kprimaryColor,
71+
),
72+
child: Text(
73+
'Apply Duration'.tr,
74+
style: TextStyle(
75+
color: themeController.isLightMode.value
76+
? kLightSecondaryTextColor
77+
: ksecondaryTextColor,
78+
),
79+
),
80+
),
81+
],
82+
),
83+
),
84+
);
85+
},
86+
child: Container(
87+
width: width * 0.91,
88+
height: height * 0.09,
89+
decoration: Utils.getCustomTileBoxDecoration(
90+
isLightMode: themeController.isLightMode.value,
91+
),
92+
child: Center(
93+
child: Padding(
94+
padding: EdgeInsets.only(left: 10, right: 10),
95+
child: ListTile(
96+
tileColor: themeController.isLightMode.value
97+
? kLightSecondaryBackgroundColor
98+
: ksecondaryBackgroundColor,
99+
title: Text(
100+
'Undo Duration'.tr,
101+
style: TextStyle(
102+
color: themeController.isLightMode.value
103+
? kLightPrimaryTextColor
104+
: kprimaryTextColor,
105+
fontSize: 15
106+
),
107+
),
108+
trailing: Wrap(
109+
crossAxisAlignment: WrapCrossAlignment.center,
110+
children: [
111+
Obx(
112+
() => Text(
113+
'${homeController.duration.value.round().toInt()} seconds',
114+
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
115+
color: themeController.isLightMode.value
116+
? kLightPrimaryTextColor
117+
: kprimaryTextColor,
118+
fontSize: 13
119+
),
120+
),
121+
),
122+
Icon(
123+
Icons.chevron_right,
124+
color: themeController.isLightMode.value
125+
? kLightPrimaryDisabledTextColor
126+
: kprimaryDisabledTextColor,
127+
),
128+
],
129+
),
130+
),
131+
),
132+
)
133+
)
134+
);
135+
}
136+
137+
}

lib/app/modules/settings/views/settings_view.dart

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
33
import 'package:get/get.dart';
44
import 'package:ultimate_alarm_clock/app/modules/home/controllers/home_controller.dart';
55
import 'package:ultimate_alarm_clock/app/modules/settings/controllers/theme_controller.dart';
6+
import 'package:ultimate_alarm_clock/app/modules/settings/views/customize_undo_duration.dart';
67

78
import 'package:ultimate_alarm_clock/app/modules/settings/views/enable_24Hour_format.dart';
89

@@ -110,6 +111,14 @@ class SettingsView extends GetView<SettingsController> {
110111
const SizedBox(
111112
height: 20,
112113
),
114+
CustomizeUndoDuration(
115+
width: width,
116+
height: height,
117+
themeController: controller.themeController
118+
),
119+
const SizedBox(
120+
height: 20,
121+
),
113122
LanguageMenu(
114123
controller: controller,
115124
height: height,

0 commit comments

Comments
 (0)