Skip to content

Commit e888e8f

Browse files
Merge pull request #39 from 100RAV-AGGARWAL/snackbar-and-dialog-box
snackbars
2 parents 6d442d5 + 95ee4a0 commit e888e8f

File tree

4 files changed

+81
-12
lines changed

4 files changed

+81
-12
lines changed

lib/services/task_details.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ class _DetailRouteState extends State<DetailRoute> {
119119
);
120120
setState(() {});
121121
Navigator.of(context).pop();
122+
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
123+
content: const Text('Task Updated'),
124+
backgroundColor: AppSettings.isDarkMode
125+
? const Color.fromARGB(255, 61, 61, 61)
126+
: const Color.fromARGB(255, 39, 39, 39),
127+
duration: const Duration(seconds: 2)));
122128
},
123129
child: const Text('Submit'),
124130
),

lib/views/profile/profile.dart

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,24 @@ class _ProfilePageState extends State<ProfilePage> {
7373
suggestedName: 'tasks-$now.txt',
7474
);
7575
},
76-
() => profilesWidget.copyConfigToNewProfile(currentProfile),
76+
() {
77+
try {
78+
profilesWidget.copyConfigToNewProfile(currentProfile);
79+
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
80+
content: const Text('Profile Config Copied'),
81+
backgroundColor: AppSettings.isDarkMode
82+
? const Color.fromARGB(255, 61, 61, 61)
83+
: const Color.fromARGB(255, 39, 39, 39),
84+
duration: const Duration(seconds: 2)));
85+
} catch (e) {
86+
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
87+
content: const Text('Profile Config Copy Failed'),
88+
backgroundColor: AppSettings.isDarkMode
89+
? const Color.fromARGB(255, 61, 61, 61)
90+
: const Color.fromARGB(255, 39, 39, 39),
91+
duration: const Duration(seconds: 2)));
92+
}
93+
},
7794
() => showDialog(
7895
context: context,
7996
builder: (context) => DeleteProfileDialog(
@@ -129,7 +146,24 @@ class ProfilesColumn extends StatelessWidget {
129146
height: 6,
130147
),
131148
ElevatedButton.icon(
132-
onPressed: addProfile,
149+
onPressed: () {
150+
try {
151+
addProfile();
152+
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
153+
content: const Text('Profile Added Successfully'),
154+
backgroundColor: AppSettings.isDarkMode
155+
? const Color.fromARGB(255, 61, 61, 61)
156+
: const Color.fromARGB(255, 39, 39, 39),
157+
duration: const Duration(seconds: 2)));
158+
} catch (e) {
159+
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
160+
content: const Text('Profile Additon Failed'),
161+
backgroundColor: AppSettings.isDarkMode
162+
? const Color.fromARGB(255, 61, 61, 61)
163+
: const Color.fromARGB(255, 39, 39, 39),
164+
duration: const Duration(seconds: 2)));
165+
}
166+
},
133167
icon: const Icon(Icons.add),
134168
label: const Text('Add new Profile'))
135169
],

lib/widgets/addTask.dart

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,26 @@ class _AddTaskBottomSheetState extends State<AddTaskBottomSheet> {
196196
.rebuild((b) => b..due = due)
197197
.rebuild((p) => p..priority = priority);
198198

199-
StorageWidget.of(context).mergeTask(task);
200-
//StorageWidget.of(context).mergeTask(prioritytask);
201-
namecontroller.text = '';
202-
due = null;
203-
priority = 'M';
204-
setState(() {});
205-
Navigator.of(context).pop();
206-
}
199+
StorageWidget.of(context).mergeTask(task);
200+
//StorageWidget.of(context).mergeTask(prioritytask);
201+
namecontroller.text = '';
202+
due = null;
203+
priority = 'M';
204+
setState(() {});
205+
Navigator.of(context).pop();
206+
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
207+
content: const Text('Task Added Successfully'),
208+
backgroundColor: AppSettings.isDarkMode
209+
? const Color.fromARGB(255, 61, 61, 61)
210+
: const Color.fromARGB(255, 39, 39, 39),
211+
duration: const Duration(seconds: 2)));
207212
} on FormatException catch (e) {
213+
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
214+
content: const Text('Task Addition Failed'),
215+
backgroundColor: AppSettings.isDarkMode
216+
? const Color.fromARGB(255, 61, 61, 61)
217+
: const Color.fromARGB(255, 39, 39, 39),
218+
duration: const Duration(seconds: 2)));
208219
log(e.toString());
209220
}
210221
},

lib/widgets/profilefunctions/deleteprofiledialog.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:taskwarrior/config/app_settings.dart';
23
import 'package:taskwarrior/widgets/taskdetails/profiles_widget.dart';
34

45
class DeleteProfileDialog extends StatelessWidget {
@@ -25,8 +26,25 @@ class DeleteProfileDialog extends StatelessWidget {
2526
),
2627
ElevatedButton(
2728
onPressed: () {
28-
ProfilesWidget.of(context).deleteProfile(profile);
29-
Navigator.of(context).pop();
29+
try {
30+
ProfilesWidget.of(context).deleteProfile(profile);
31+
Navigator.of(context).pop();
32+
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
33+
content: Text(
34+
'Profile: ${profile.characters} Deleted Successfully'),
35+
backgroundColor: AppSettings.isDarkMode
36+
? const Color.fromARGB(255, 61, 61, 61)
37+
: const Color.fromARGB(255, 39, 39, 39),
38+
duration: const Duration(seconds: 2)));
39+
} catch (e) {
40+
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
41+
content:
42+
Text('Profile: ${profile.characters} Deletion Failed'),
43+
backgroundColor: AppSettings.isDarkMode
44+
? const Color.fromARGB(255, 61, 61, 61)
45+
: const Color.fromARGB(255, 39, 39, 39),
46+
duration: const Duration(seconds: 2)));
47+
}
3048
},
3149
child: const Text('Confirm'),
3250
),

0 commit comments

Comments
 (0)