Skip to content

Commit 9b3ed9e

Browse files
committed
fix(detailRoute): improve navigation logic and debug messages for unsaved changes
1 parent 61783f0 commit 9b3ed9e

File tree

2 files changed

+53
-37
lines changed

2 files changed

+53
-37
lines changed

lib/app/modules/detailRoute/views/detail_route_view.dart

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ class DetailRouteView extends GetView<DetailRouteController> {
2828
return WillPopScope(
2929
onWillPop: () async {
3030
if (!controller.onEdit.value) {
31+
debugPrint(
32+
'DetailRouteView: No edits made, navigating back without prompt.');
3133
// Get.offAll(() => const HomeView());
32-
Get.back();
34+
Navigator.of(context).pop();
3335
// Get.toNamed(Routes.HOME);
3436
return false;
3537
}
38+
debugPrint(
39+
'DetailRouteView: Unsaved edits detected, prompting user for action.');
3640

3741
bool? save = await showDialog(
3842
context: context,
@@ -50,10 +54,14 @@ class DetailRouteView extends GetView<DetailRouteController> {
5054
actions: [
5155
TextButton(
5256
onPressed: () {
53-
controller.saveChanges();
54-
// Get.offAll(() => const HomeView());
57+
// Get.back(); // Close the dialog first
58+
// // Wait for dialog to fully close before showing snackbar
59+
// Future.delayed(const Duration(milliseconds: 100), () {
60+
// controller.saveChanges();
61+
// });
5562

56-
Get.back();
63+
controller.saveChanges();
64+
Navigator.of(context).pop(true);
5765
},
5866
child: Text(
5967
SentenceManager(
@@ -69,7 +77,7 @@ class DetailRouteView extends GetView<DetailRouteController> {
6977
onPressed: () {
7078
// Get.offAll(() => const HomeView());
7179

72-
Get.back();
80+
Navigator.of(context).pop();
7381
},
7482
child: Text(
7583
SentenceManager(
@@ -83,7 +91,7 @@ class DetailRouteView extends GetView<DetailRouteController> {
8391
),
8492
TextButton(
8593
onPressed: () {
86-
Get.back();
94+
Navigator.of(context).pop(false);
8795
},
8896
child: Text(
8997
SentenceManager(
@@ -251,7 +259,7 @@ class AttributeWidget extends StatelessWidget {
251259
Theme.of(context).extension<TaskwarriorColorTheme>()!;
252260
// Get the controller to check if the task is read-only
253261
final DetailRouteController controller = Get.find<DetailRouteController>();
254-
262+
255263
// Always allow status to be edited, but respect read-only for other attributes
256264
final bool isEditable = !controller.isReadOnly.value || name == 'status';
257265

@@ -323,9 +331,10 @@ class AttributeWidget extends StatelessWidget {
323331
isEditable: isEditable,
324332
);
325333
default:
326-
final Color? textColor = (isEditable && !['entry', 'modified', 'urgency'].contains(name))
327-
? tColors.primaryTextColor
328-
: tColors.primaryDisabledTextColor;
334+
final Color? textColor =
335+
(isEditable && !['entry', 'modified', 'urgency'].contains(name))
336+
? tColors.primaryTextColor
337+
: tColors.primaryDisabledTextColor;
329338

330339
return Card(
331340
color: tColors.secondaryBackgroundColor,

lib/app/modules/home/views/tasks_builder.dart

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class TasksBuilder extends StatelessWidget {
5353

5454
void saveChanges(
5555
BuildContext context, Modify modify, String id, String newValue) async {
56-
TaskwarriorColorTheme tColors = Theme.of(context).extension<TaskwarriorColorTheme>()!;
56+
TaskwarriorColorTheme tColors =
57+
Theme.of(context).extension<TaskwarriorColorTheme>()!;
5758
var now = DateTime.now().toUtc();
5859
modify.save(
5960
modified: () => now,
@@ -110,32 +111,37 @@ class TasksBuilder extends StatelessWidget {
110111
@override
111112
Widget build(BuildContext context) {
112113
// print(taskData);
113-
TaskwarriorColorTheme tColors = Theme.of(context).extension<TaskwarriorColorTheme>()!;
114+
TaskwarriorColorTheme tColors =
115+
Theme.of(context).extension<TaskwarriorColorTheme>()!;
114116
var storageWidget = Get.find<HomeController>();
115117
return Scaffold(
116118
floatingActionButtonLocation:
117119
FloatingActionButtonLocation.miniStartFloat,
118-
floatingActionButton: showbtn ? AnimatedOpacity(
119-
duration: const Duration(milliseconds: 100), //show/hide animation
120-
opacity: showbtn ? 1.0 : 0.0, //set obacity to 1 on visible, or hide
121-
child: FloatingActionButton(
122-
heroTag: "btn2",
123-
onPressed: () {
124-
scrollController.animateTo(
125-
//go to top of scroll
126-
0, //scroll offset to go
127-
duration:
128-
const Duration(milliseconds: 500), //duration of scroll
129-
curve: Curves.fastLinearToSlowEaseIn //scroll type
130-
);
131-
},
132-
backgroundColor: tColors.primaryTextColor,
133-
child: Icon(
134-
Icons.arrow_upward,
135-
color: tColors.secondaryBackgroundColor,
136-
),
137-
),
138-
) : null,
120+
floatingActionButton: showbtn
121+
? AnimatedOpacity(
122+
duration:
123+
const Duration(milliseconds: 100), //show/hide animation
124+
opacity:
125+
showbtn ? 1.0 : 0.0, //set obacity to 1 on visible, or hide
126+
child: FloatingActionButton(
127+
heroTag: "btn2",
128+
onPressed: () {
129+
scrollController.animateTo(
130+
//go to top of scroll
131+
0, //scroll offset to go
132+
duration: const Duration(
133+
milliseconds: 500), //duration of scroll
134+
curve: Curves.fastLinearToSlowEaseIn //scroll type
135+
);
136+
},
137+
backgroundColor: tColors.primaryTextColor,
138+
child: Icon(
139+
Icons.arrow_upward,
140+
color: tColors.secondaryBackgroundColor,
141+
),
142+
),
143+
)
144+
: null,
139145
backgroundColor: Colors.transparent,
140146
body: Obx(
141147
() => taskData.isEmpty
@@ -152,8 +158,7 @@ class TasksBuilder extends StatelessWidget {
152158
style: TextStyle(
153159
fontFamily: FontFamily.poppins,
154160
fontSize: TaskWarriorFonts.fontSizeLarge,
155-
color: tColors.primaryTextColor
156-
),
161+
color: tColors.primaryTextColor),
157162
// style: GoogleFonts.poppins(
158163
// fontSize: TaskWarriorFonts.fontSizeLarge,
159164
// color: AppSettings.isDarkMode
@@ -193,7 +198,8 @@ class TasksBuilder extends StatelessWidget {
193198
}
194199
},
195200
icon: Icons.done,
196-
label: SentenceManager(currentLanguage: selectedLanguage)
201+
label: SentenceManager(
202+
currentLanguage: selectedLanguage)
197203
.sentences
198204
.complete,
199205
backgroundColor: TaskWarriorColors.green,
@@ -222,7 +228,8 @@ class TasksBuilder extends StatelessWidget {
222228
}
223229
},
224230
icon: Icons.delete,
225-
label: SentenceManager(currentLanguage: selectedLanguage)
231+
label: SentenceManager(
232+
currentLanguage: selectedLanguage)
226233
.sentences
227234
.delete,
228235
backgroundColor: TaskWarriorColors.red,

0 commit comments

Comments
 (0)