Skip to content

Commit 07a9051

Browse files
committed
moved option of delete all tasks to settings page
1 parent 72913ad commit 07a9051

File tree

10 files changed

+180
-119
lines changed

10 files changed

+180
-119
lines changed

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

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -78,74 +78,6 @@ class NavDrawer extends StatelessWidget {
7878
color: tColors.dialogBackgroundColor,
7979
height: Get.height * 0.03,
8080
),
81-
Obx(() => Visibility(
82-
visible: homeController.taskchampion.value,
83-
child: NavDrawerMenuItem(
84-
icon: Icons.delete,
85-
text: SentenceManager(
86-
currentLanguage: homeController.selectedLanguage.value,
87-
).sentences.deleteTaskTitle,
88-
onTap: () {
89-
showDialog<void>(
90-
context: context,
91-
builder: (BuildContext context) {
92-
return Utils.showAlertDialog(
93-
title: Text(
94-
SentenceManager(
95-
currentLanguage:
96-
homeController.selectedLanguage.value,
97-
).sentences.deleteTaskConfirmation,
98-
style: TextStyle(
99-
color: tColors.primaryTextColor,
100-
),
101-
),
102-
content: Text(
103-
SentenceManager(
104-
currentLanguage:
105-
homeController.selectedLanguage.value,
106-
).sentences.deleteTaskWarning,
107-
style: TextStyle(
108-
color: tColors.primaryDisabledTextColor,
109-
),
110-
),
111-
actions: <Widget>[
112-
TextButton(
113-
child: Text(
114-
SentenceManager(
115-
currentLanguage:
116-
homeController.selectedLanguage.value,
117-
).sentences.homePageCancel,
118-
style: TextStyle(
119-
color: tColors.primaryTextColor,
120-
),
121-
),
122-
onPressed: () {
123-
Navigator.of(context)
124-
.pop(); // Close the dialog
125-
},
126-
),
127-
TextButton(
128-
child: Text(
129-
SentenceManager(
130-
currentLanguage:
131-
homeController.selectedLanguage.value,
132-
).sentences.navDrawerConfirm,
133-
style: TextStyle(
134-
color: tColors.primaryTextColor,
135-
),
136-
),
137-
onPressed: () {
138-
homeController.deleteAllTasksInDB();
139-
Navigator.of(context)
140-
.pop(); // Close the dialog
141-
},
142-
),
143-
],
144-
);
145-
},
146-
);
147-
}),
148-
)),
14981
Obx(
15082
() => NavDrawerMenuItem(
15183
icon: Icons.person_rounded,

lib/app/modules/settings/controllers/settings_controller.dart

Lines changed: 65 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'package:path/path.dart' as path;
2020

2121
import 'package:taskwarrior/app/modules/splash/controllers/splash_controller.dart';
2222
import 'package:taskwarrior/app/utils/themes/theme_extension.dart';
23+
import 'package:taskwarrior/app/v3/db/task_database.dart';
2324

2425
class SettingsController extends GetxController {
2526
RxBool isMovingDirectory = false.obs;
@@ -46,71 +47,72 @@ class SettingsController extends GetxController {
4647
}
4748

4849
void pickDirectory(BuildContext context) {
49-
TaskwarriorColorTheme tColors = Theme.of(context).extension<TaskwarriorColorTheme>()!;
50+
TaskwarriorColorTheme tColors =
51+
Theme.of(context).extension<TaskwarriorColorTheme>()!;
5052
FilePicker.platform.getDirectoryPath().then((value) async {
5153
if (value != null) {
5254
isMovingDirectory.value = true;
5355
update();
5456
// InheritedProfiles profilesWidget = ProfilesWidget.of(context);
5557
var profilesWidget = Get.find<SplashController>();
5658
Directory source = profilesWidget.baseDirectory();
57-
Directory destination = Directory(value);
59+
Directory destination = Directory(value);
5860
moveDirectory(source.path, destination.path).then((value) async {
5961
isMovingDirectory.value = false;
6062
update();
6163
if (value == "same") {
6264
return;
63-
} else if (value == "success") {
65+
} else if (value == "success") {
6466
profilesWidget.setBaseDirectory(destination);
6567
SharedPreferences prefs = await SharedPreferences.getInstance();
6668
prefs.setString('baseDirectory', destination.path);
6769
baseDirectory.value = destination.path;
68-
Get.snackbar(
69-
'Success',
70-
'Base directory moved successfully',
71-
snackPosition: SnackPosition.BOTTOM,
72-
duration: const Duration(seconds: 2),
73-
);
74-
} else {
75-
Get.dialog(
76-
Utils.showAlertDialog(
77-
title: Text(
78-
'Error',
79-
style: GoogleFonts.poppins(
80-
fontWeight: FontWeight.bold,
81-
fontSize: TaskWarriorFonts.fontSizeMedium,
82-
color: tColors.primaryTextColor,
83-
),
70+
Get.snackbar(
71+
'Success',
72+
'Base directory moved successfully',
73+
snackPosition: SnackPosition.BOTTOM,
74+
duration: const Duration(seconds: 2),
75+
);
76+
} else {
77+
Get.dialog(
78+
Utils.showAlertDialog(
79+
title: Text(
80+
'Error',
81+
style: GoogleFonts.poppins(
82+
fontWeight: FontWeight.bold,
83+
fontSize: TaskWarriorFonts.fontSizeMedium,
84+
color: tColors.primaryTextColor,
8485
),
85-
content: Text(
86-
value == "nested"
87-
? "Cannot move to a nested directory"
88-
: value == "not-empty"
89-
? "Destination directory is not empty"
90-
: value == "not-permitted"
91-
? "Selected folder can't be written to (Android SAF). Please choose a different folder."
92-
: "An error occurred",
93-
style: GoogleFonts.poppins(
94-
color: TaskWarriorColors.grey,
95-
fontSize: TaskWarriorFonts.fontSizeSmall,
96-
),
86+
),
87+
content: Text(
88+
value == "nested"
89+
? "Cannot move to a nested directory"
90+
: value == "not-empty"
91+
? "Destination directory is not empty"
92+
: value == "not-permitted"
93+
? "Selected folder can't be written to (Android SAF). Please choose a different folder."
94+
: "An error occurred",
95+
style: GoogleFonts.poppins(
96+
color: TaskWarriorColors.grey,
97+
fontSize: TaskWarriorFonts.fontSizeSmall,
9798
),
98-
actions: [
99-
TextButton(
100-
onPressed: () {
101-
Get.back();
102-
},
103-
child: Text(
104-
'OK',
105-
style: GoogleFonts.poppins(
106-
color: tColors.primaryTextColor,
107-
),
108-
),
109-
)
110-
],
11199
),
112-
);
113-
}
100+
actions: [
101+
TextButton(
102+
onPressed: () {
103+
Get.back();
104+
},
105+
child: Text(
106+
'OK',
107+
style: GoogleFonts.poppins(
108+
color: tColors.primaryTextColor,
109+
),
110+
),
111+
)
112+
],
113+
),
114+
);
115+
}
114116
});
115117
}
116118
});
@@ -125,9 +127,9 @@ class SettingsController extends GetxController {
125127
return "nested";
126128
}
127129

128-
Directory toDir = Directory(toDirectory);
129-
// Ensure destination exists before checking contents
130-
await toDir.create(recursive: true);
130+
Directory toDir = Directory(toDirectory);
131+
// Ensure destination exists before checking contents
132+
await toDir.create(recursive: true);
131133
final length = await toDir.list().length;
132134
if (length > 0) {
133135
return "not-empty";
@@ -143,7 +145,10 @@ class SettingsController extends GetxController {
143145
} on FileSystemException catch (e) {
144146
// Map common permission error to a friendly status
145147
if (e.osError?.errorCode == 1 ||
146-
(e.osError?.message.toLowerCase().contains("operation not permitted") ?? false)) {
148+
(e.osError?.message
149+
.toLowerCase()
150+
.contains("operation not permitted") ??
151+
false)) {
147152
return "not-permitted";
148153
}
149154
return "error";
@@ -156,7 +161,10 @@ class SettingsController extends GetxController {
156161
return "success";
157162
} on FileSystemException catch (e) {
158163
if (e.osError?.errorCode == 1 ||
159-
(e.osError?.message.toLowerCase().contains("operation not permitted") ?? false)) {
164+
(e.osError?.message
165+
.toLowerCase()
166+
.contains("operation not permitted") ??
167+
false)) {
160168
return "not-permitted";
161169
}
162170
return "error";
@@ -200,6 +208,12 @@ class SettingsController extends GetxController {
200208
}
201209
}
202210

211+
Future<void> deleteAllTasksInDB() async {
212+
var taskDatabase = TaskDatabase();
213+
await taskDatabase.deleteAllTasksInDB();
214+
debugPrint('Deleted all tasks from db');
215+
}
216+
203217
RxBool isSyncOnStartActivel = false.obs;
204218
RxBool isSyncOnTaskCreateActivel = false.obs;
205219
RxBool delaytask = false.obs;

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

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import 'package:flutter/material.dart';
44
import 'package:get/get.dart';
55

66
import 'package:google_fonts/google_fonts.dart';
7+
import 'package:shared_preferences/shared_preferences.dart';
78
import 'package:taskwarrior/app/routes/app_pages.dart';
89
import 'package:taskwarrior/app/utils/app_settings/app_settings.dart';
910
import 'package:taskwarrior/app/utils/constants/taskwarrior_fonts.dart';
11+
import 'package:taskwarrior/app/utils/constants/utilites.dart';
1012
import 'package:taskwarrior/app/utils/language/sentence_manager.dart';
1113
import 'package:taskwarrior/app/utils/themes/theme_extension.dart';
1214
import '../controllers/settings_controller.dart';
@@ -23,6 +25,11 @@ class SettingsPageBody extends StatelessWidget {
2325

2426
const SettingsPageBody({required this.controller, super.key});
2527

28+
Future<bool> _getFlag() async {
29+
final prefs = await SharedPreferences.getInstance();
30+
return prefs.getBool("settings_taskc") ?? false;
31+
}
32+
2633
@override
2734
Widget build(BuildContext context) {
2835
TaskwarriorColorTheme tColors =
@@ -141,6 +148,91 @@ class SettingsPageBody extends StatelessWidget {
141148
Get.toNamed(Routes.LOGS);
142149
},
143150
icon: const Icon(Icons.login)),
151+
),
152+
const Divider(),
153+
FutureBuilder<bool>(
154+
future: _getFlag(), // method to fetch SharedPreference value
155+
builder: (context, snapshot) {
156+
switch (snapshot.connectionState) {
157+
case ConnectionState.waiting:
158+
return const SizedBox
159+
.shrink(); // show nothing while loading
160+
case ConnectionState.done:
161+
final show = snapshot.data ?? false;
162+
if (!show) return const SizedBox.shrink(); // hide if false
163+
return SettingsPageListTile(
164+
title: SentenceManager(
165+
currentLanguage: AppSettings.selectedLanguage,
166+
).sentences.deleteTaskTitle,
167+
subTitle: SentenceManager(
168+
currentLanguage: AppSettings.selectedLanguage,
169+
).sentences.deleteAllTasksWillBeMarkedAsDeleted,
170+
trailing: IconButton(
171+
onPressed: () {
172+
showDialog<void>(
173+
context: context,
174+
builder: (BuildContext context) {
175+
return Utils.showAlertDialog(
176+
title: Text(
177+
SentenceManager(
178+
currentLanguage:
179+
AppSettings.selectedLanguage,
180+
).sentences.deleteTaskConfirmation,
181+
style: TextStyle(
182+
color: tColors.primaryTextColor,
183+
),
184+
),
185+
content: Text(
186+
SentenceManager(
187+
currentLanguage:
188+
AppSettings.selectedLanguage,
189+
).sentences.deleteTaskWarning,
190+
style: TextStyle(
191+
color: tColors.primaryDisabledTextColor,
192+
),
193+
),
194+
actions: <Widget>[
195+
TextButton(
196+
child: Text(
197+
SentenceManager(
198+
currentLanguage:
199+
AppSettings.selectedLanguage,
200+
).sentences.homePageCancel,
201+
style: TextStyle(
202+
color: tColors.primaryTextColor,
203+
),
204+
),
205+
onPressed: () {
206+
Navigator.of(context).pop();
207+
},
208+
),
209+
TextButton(
210+
child: Text(
211+
SentenceManager(
212+
currentLanguage:
213+
AppSettings.selectedLanguage,
214+
).sentences.navDrawerConfirm,
215+
style: TextStyle(
216+
color: tColors.primaryTextColor,
217+
),
218+
),
219+
onPressed: () {
220+
controller.deleteAllTasksInDB();
221+
Navigator.of(context).pop();
222+
},
223+
),
224+
],
225+
);
226+
},
227+
);
228+
},
229+
icon: const Icon(Icons.delete),
230+
),
231+
);
232+
default:
233+
return const SizedBox.shrink();
234+
}
235+
},
144236
)
145237
],
146238
);

lib/app/utils/language/bengali_sentences.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ class BengaliSentences extends Sentences {
208208
@override
209209
String get deleteTaskWarning =>
210210
'এই পদক্ষেপটি অপরিবর্তনীয় এবং সমস্ত স্থানীয়ভাবে সংরক্ষিত টাস্ক মুছে ফেলবে।';
211+
@override
212+
String get deleteAllTasksWillBeMarkedAsDeleted =>
213+
'\u099f\u09be\u09b8\u09cd\u0995\u09b0 \u09ac\u09a7\u09be \u09b8\u09be\u09b0\u09cd\u099a\u09c7 \u09a8\u09be\u09b9\u09c0\u0995\u09c7 \u0995\u09b0\u09c1\u09a8\u099f\u09be\u09b8\u09cd\u0995 \u0995\u09be\u09b0\u09cd\u092f\u09cb\u09b0 \u09b9\u09be\u09b7\u09c7 \u0995\u09b0\u09be\u09b8\u09cd\u09a4\u09c7 \u099f\u09be\u09b8\u09cd\u0995 \u0995\u09b0\u09c7\u0964';
211214

212215
@override
213216
String get profilePageProfile => 'প্রোফাইল';

lib/app/utils/language/english_sentences.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ class EnglishSentences extends Sentences {
223223
String get deleteTaskWarning =>
224224
'The action is irreversible and will delete all the tasks that are stored locally.';
225225

226+
@override
227+
String get deleteAllTasksWillBeMarkedAsDeleted =>
228+
'This will mark all tasks as deleted and will not be shown in app';
229+
226230
@override
227231
String get profilePageProfile => 'Profile';
228232
@override

lib/app/utils/language/french_sentences.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ class FrenchSentences extends Sentences {
212212
String get deleteTaskWarning =>
213213
'Cette action est irréversible et supprimera toutes les tâches stockées localement.';
214214

215+
@override
216+
String get deleteAllTasksWillBeMarkedAsDeleted =>
217+
'Cela marquera toutes les tâches comme supprimées et elles ne seront pas affichées dans l\'application.';
218+
215219
@override
216220
String get profilePageProfile => 'Profil';
217221
@override

0 commit comments

Comments
 (0)