Skip to content

Commit 17f97ea

Browse files
authored
Merge pull request #313 from its-me-abhishek/dialog-function
Added showAlertDialog function in utilities.dart
2 parents 73b7c01 + 3f9f58f commit 17f97ea

File tree

11 files changed

+91
-147
lines changed

11 files changed

+91
-147
lines changed

lib/drawer/nav_drawer.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:taskwarrior/config/app_settings.dart';
88
import 'package:taskwarrior/config/taskwarriorcolors.dart';
99
import 'package:taskwarrior/config/taskwarriorfonts.dart';
1010
import 'package:taskwarrior/model/storage/storage_widget.dart';
11+
import 'package:taskwarrior/utility/utilities.dart';
1112
import 'package:taskwarrior/views/about/about.dart';
1213
import 'package:taskwarrior/views/profile/profile.dart';
1314
import 'package:taskwarrior/views/reports/reports_home.dart';
@@ -211,16 +212,7 @@ Future<void> _showExitConfirmationDialog(BuildContext context) async {
211212
context: context,
212213
barrierDismissible: false, // Prevents closing the dialog by tapping outside
213214
builder: (BuildContext context) {
214-
return AlertDialog(
215-
surfaceTintColor: AppSettings.isDarkMode
216-
? TaskWarriorColors.kdialogBackGroundColor
217-
: TaskWarriorColors.kLightDialogBackGroundColor,
218-
shadowColor: AppSettings.isDarkMode
219-
? TaskWarriorColors.kdialogBackGroundColor
220-
: TaskWarriorColors.kLightDialogBackGroundColor,
221-
backgroundColor: AppSettings.isDarkMode
222-
? TaskWarriorColors.kdialogBackGroundColor
223-
: TaskWarriorColors.kLightDialogBackGroundColor,
215+
return Utils.showAlertDialog(
224216
title: Text(
225217
'Exit App',
226218
style: TextStyle(

lib/services/task_details.dart

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:taskwarrior/config/app_settings.dart';
1010
import 'package:taskwarrior/config/taskwarriorcolors.dart';
1111
import 'package:taskwarrior/config/taskwarriorfonts.dart';
1212
import 'package:taskwarrior/model/storage/storage_widget.dart';
13+
import 'package:taskwarrior/utility/utilities.dart';
1314
import 'package:taskwarrior/views/home/home.dart';
1415
import 'package:taskwarrior/widgets/pallete.dart';
1516
import 'package:taskwarrior/widgets/taskdetails.dart';
@@ -86,16 +87,7 @@ class _DetailRouteState extends State<DetailRoute> {
8687
return showDialog(
8788
context: context,
8889
builder: (context) {
89-
return AlertDialog(
90-
surfaceTintColor: AppSettings.isDarkMode
91-
? TaskWarriorColors.kdialogBackGroundColor
92-
: TaskWarriorColors.kLightDialogBackGroundColor,
93-
shadowColor: AppSettings.isDarkMode
94-
? TaskWarriorColors.kdialogBackGroundColor
95-
: TaskWarriorColors.kLightDialogBackGroundColor,
96-
backgroundColor: AppSettings.isDarkMode
97-
? TaskWarriorColors.kdialogBackGroundColor
98-
: TaskWarriorColors.kLightDialogBackGroundColor,
90+
return Utils.showAlertDialog(
9991
title: Text(
10092
'Do you want to save changes?',
10193
style: TextStyle(
@@ -219,16 +211,7 @@ class _DetailRouteState extends State<DetailRoute> {
219211
showDialog(
220212
context: context,
221213
builder: (context) {
222-
return AlertDialog(
223-
surfaceTintColor: AppSettings.isDarkMode
224-
? TaskWarriorColors.kdialogBackGroundColor
225-
: TaskWarriorColors.kLightDialogBackGroundColor,
226-
shadowColor: AppSettings.isDarkMode
227-
? TaskWarriorColors.kdialogBackGroundColor
228-
: TaskWarriorColors.kLightDialogBackGroundColor,
229-
backgroundColor: AppSettings.isDarkMode
230-
? TaskWarriorColors.kdialogBackGroundColor
231-
: TaskWarriorColors.kLightDialogBackGroundColor,
214+
return Utils.showAlertDialog(
232215
scrollable: true,
233216
title: Text(
234217
'Review changes:',

lib/taskserver/ntaskserver.dart

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:get/get.dart';
33
import 'package:loggy/loggy.dart';
44
import 'package:taskwarrior/config/taskwarriorcolors.dart';
55
import 'package:taskwarrior/config/taskwarriorfonts.dart';
6+
import 'package:taskwarrior/utility/utilities.dart';
67
import 'package:taskwarrior/widgets/taskdetails/profiles_widget.dart';
78
// ignore_for_file: use_build_context_synchronously
89

@@ -77,16 +78,7 @@ class _ManageTaskServerState extends State<ManageTaskServer> {
7778
context: context,
7879
barrierDismissible: false,
7980
builder: (context) {
80-
return AlertDialog(
81-
surfaceTintColor: AppSettings.isDarkMode
82-
? TaskWarriorColors.kdialogBackGroundColor
83-
: TaskWarriorColors.kLightDialogBackGroundColor,
84-
shadowColor: AppSettings.isDarkMode
85-
? TaskWarriorColors.kdialogBackGroundColor
86-
: TaskWarriorColors.kLightDialogBackGroundColor,
87-
backgroundColor: AppSettings.isDarkMode
88-
? TaskWarriorColors.kdialogBackGroundColor
89-
: TaskWarriorColors.kLightDialogBackGroundColor,
81+
return Utils.showAlertDialog(
9082
title: const Text('Fetching statistics...'),
9183
content: const Column(
9284
mainAxisSize: MainAxisSize.min,
@@ -114,16 +106,7 @@ class _ManageTaskServerState extends State<ManageTaskServer> {
114106
// Show statistics in a dialog
115107
await showDialog(
116108
context: context,
117-
builder: (context) => AlertDialog(
118-
surfaceTintColor: AppSettings.isDarkMode
119-
? TaskWarriorColors.kdialogBackGroundColor
120-
: TaskWarriorColors.kLightDialogBackGroundColor,
121-
shadowColor: AppSettings.isDarkMode
122-
? TaskWarriorColors.kdialogBackGroundColor
123-
: TaskWarriorColors.kLightDialogBackGroundColor,
124-
backgroundColor: AppSettings.isDarkMode
125-
? TaskWarriorColors.kdialogBackGroundColor
126-
: TaskWarriorColors.kLightDialogBackGroundColor,
109+
builder: (context) => Utils.showAlertDialog(
127110
scrollable: true,
128111
title: Text(
129112
'Statistics:',
@@ -840,7 +823,9 @@ class _PemWidgetState extends State<PemWidget> {
840823
var name = widget.storage.guiPemFiles.pemFilename(widget.pem);
841824
String identifier = "";
842825
try {
843-
identifier = fingerprint(contents!).toUpperCase();
826+
if (contents != null) {
827+
identifier = fingerprint(contents).toUpperCase(); // Null check removed
828+
}
844829
} catch (e) {
845830
debugPrint(e.toString());
846831
}

lib/utility/utilities.dart

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import 'package:flutter/material.dart';
12
import 'package:intl/intl.dart';
3+
import 'package:taskwarrior/config/app_settings.dart';
4+
import 'package:taskwarrior/config/taskwarriorcolors.dart';
25

36
class Utils {
47
static String getWeekNumber(DateTime? date) {
@@ -48,4 +51,65 @@ class Utils {
4851
return '';
4952
}
5053
}
54+
55+
static AlertDialog showAlertDialog({
56+
Key? key,
57+
Widget? icon,
58+
EdgeInsetsGeometry? iconPadding,
59+
Color? iconColor,
60+
Widget? title,
61+
EdgeInsetsGeometry? titlePadding,
62+
TextStyle? titleTextStyle,
63+
Widget? content,
64+
EdgeInsetsGeometry? contentPadding,
65+
TextStyle? contentTextStyle,
66+
List<Widget>? actions,
67+
EdgeInsetsGeometry? actionsPadding,
68+
MainAxisAlignment? actionsAlignment,
69+
OverflowBarAlignment? actionsOverflowAlignment,
70+
VerticalDirection? actionsOverflowDirection,
71+
double? actionsOverflowButtonSpacing,
72+
EdgeInsetsGeometry? buttonPadding,
73+
Color? backgroundColor,
74+
double? elevation,
75+
Color? shadowColor,
76+
Color? surfaceTintColor,
77+
String? semanticLabel,
78+
Clip clipBehavior = Clip.none,
79+
ShapeBorder? shape,
80+
AlignmentGeometry? alignment,
81+
bool scrollable = false,
82+
}) {
83+
return AlertDialog(
84+
surfaceTintColor: AppSettings.isDarkMode
85+
? TaskWarriorColors.kdialogBackGroundColor
86+
: TaskWarriorColors.kLightDialogBackGroundColor,
87+
shadowColor: AppSettings.isDarkMode
88+
? TaskWarriorColors.kdialogBackGroundColor
89+
: TaskWarriorColors.kLightDialogBackGroundColor,
90+
backgroundColor: AppSettings.isDarkMode
91+
? TaskWarriorColors.kdialogBackGroundColor
92+
: TaskWarriorColors.kLightDialogBackGroundColor,
93+
key: key,
94+
title: title,
95+
titlePadding: titlePadding,
96+
titleTextStyle: titleTextStyle,
97+
content: content,
98+
contentPadding: contentPadding,
99+
contentTextStyle: contentTextStyle,
100+
actions: actions,
101+
actionsPadding: actionsPadding,
102+
actionsAlignment: actionsAlignment,
103+
actionsOverflowAlignment: actionsOverflowAlignment,
104+
actionsOverflowDirection: actionsOverflowDirection,
105+
actionsOverflowButtonSpacing: actionsOverflowButtonSpacing,
106+
buttonPadding: buttonPadding,
107+
elevation: elevation,
108+
semanticLabel: semanticLabel,
109+
clipBehavior: clipBehavior,
110+
shape: shape,
111+
alignment: alignment,
112+
scrollable: scrollable,
113+
);
114+
}
51115
}

lib/views/profile/profile.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:taskwarrior/config/app_settings.dart';
55
import 'package:taskwarrior/config/taskwarriorcolors.dart';
66
import 'package:taskwarrior/model/storage/savefile.dart';
77
import 'package:taskwarrior/taskserver/ntaskserver.dart';
8+
import 'package:taskwarrior/utility/utilities.dart';
89
import 'package:taskwarrior/widgets/pallete.dart';
910
import 'package:taskwarrior/widgets/profilefunctions.dart';
1011
import 'package:taskwarrior/widgets/taskdetails.dart';
@@ -85,16 +86,7 @@ class _ProfilePageState extends State<ProfilePage> {
8586
showDialog(
8687
context: context,
8788
builder: (BuildContext context) {
88-
return AlertDialog(
89-
surfaceTintColor: AppSettings.isDarkMode
90-
? TaskWarriorColors.kdialogBackGroundColor
91-
: TaskWarriorColors.kLightDialogBackGroundColor,
92-
shadowColor: AppSettings.isDarkMode
93-
? TaskWarriorColors.kdialogBackGroundColor
94-
: TaskWarriorColors.kLightDialogBackGroundColor,
95-
backgroundColor: AppSettings.isDarkMode
96-
? TaskWarriorColors.kdialogBackGroundColor
97-
: TaskWarriorColors.kLightDialogBackGroundColor,
89+
return Utils.showAlertDialog(
9890
title: Text(
9991
"Export Format",
10092
style: TextStyle(

lib/views/settings/settings.dart

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:file_picker/file_picker.dart';
1010
import 'package:taskwarrior/config/app_settings.dart';
1111
import 'package:taskwarrior/config/taskwarriorcolors.dart';
1212
import 'package:taskwarrior/config/taskwarriorfonts.dart';
13+
import 'package:taskwarrior/utility/utilities.dart';
1314
import 'package:taskwarrior/widgets/pallete.dart';
1415
import 'package:taskwarrior/widgets/taskdetails/profiles_widget.dart';
1516

@@ -260,22 +261,7 @@ class _SettingsPageState extends State<SettingsPage> {
260261
showDialog(
261262
context: context,
262263
builder: (BuildContext context) {
263-
return AlertDialog(
264-
surfaceTintColor: AppSettings.isDarkMode
265-
? TaskWarriorColors
266-
.kdialogBackGroundColor
267-
: TaskWarriorColors
268-
.kLightDialogBackGroundColor,
269-
shadowColor: AppSettings.isDarkMode
270-
? TaskWarriorColors
271-
.kdialogBackGroundColor
272-
: TaskWarriorColors
273-
.kLightDialogBackGroundColor,
274-
backgroundColor: AppSettings.isDarkMode
275-
? TaskWarriorColors
276-
.kdialogBackGroundColor
277-
: TaskWarriorColors
278-
.kLightDialogBackGroundColor,
264+
return Utils.showAlertDialog(
279265
title: Text(
280266
'Reset to default',
281267
style: GoogleFonts.poppins(
@@ -414,16 +400,7 @@ class _SettingsPageState extends State<SettingsPage> {
414400
showDialog(
415401
context: context,
416402
builder: (BuildContext context) {
417-
return AlertDialog(
418-
surfaceTintColor: AppSettings.isDarkMode
419-
? TaskWarriorColors.kdialogBackGroundColor
420-
: TaskWarriorColors.kLightDialogBackGroundColor,
421-
shadowColor: AppSettings.isDarkMode
422-
? TaskWarriorColors.kdialogBackGroundColor
423-
: TaskWarriorColors.kLightDialogBackGroundColor,
424-
backgroundColor: AppSettings.isDarkMode
425-
? TaskWarriorColors.kdialogBackGroundColor
426-
: TaskWarriorColors.kLightDialogBackGroundColor,
403+
return Utils.showAlertDialog(
427404
title: Text(
428405
'Error',
429406
style: GoogleFonts.poppins(

lib/widgets/add_Task.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'package:taskwarrior/config/taskwarriorcolors.dart';
1212
import 'package:taskwarrior/config/taskwarriorfonts.dart';
1313
import 'package:taskwarrior/controller/WidgetController.dart';
1414
import 'package:taskwarrior/model/storage/storage_widget.dart';
15+
import 'package:taskwarrior/utility/utilities.dart';
1516
import 'package:taskwarrior/widgets/taskfunctions/taskparser.dart';
1617
import 'package:taskwarrior/widgets/taskw.dart';
1718

@@ -49,16 +50,7 @@ class _AddTaskBottomSheetState extends State<AddTaskBottomSheet> {
4950

5051
return Center(
5152
child: SingleChildScrollView(
52-
child: AlertDialog(
53-
surfaceTintColor: AppSettings.isDarkMode
54-
? TaskWarriorColors.kdialogBackGroundColor
55-
: TaskWarriorColors.kLightDialogBackGroundColor,
56-
shadowColor: AppSettings.isDarkMode
57-
? TaskWarriorColors.kdialogBackGroundColor
58-
: TaskWarriorColors.kLightDialogBackGroundColor,
59-
backgroundColor: AppSettings.isDarkMode
60-
? TaskWarriorColors.kdialogBackGroundColor
61-
: TaskWarriorColors.kLightDialogBackGroundColor,
53+
child: Utils.showAlertDialog(
6254
title: Center(
6355
child: Text(
6456
title,

lib/widgets/profilefunctions/deleteprofiledialog.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22

33
import 'package:taskwarrior/config/app_settings.dart';
44
import 'package:taskwarrior/config/taskwarriorcolors.dart';
5+
import 'package:taskwarrior/utility/utilities.dart';
56
import 'package:taskwarrior/widgets/taskdetails/profiles_widget.dart';
67

78
class DeleteProfileDialog extends StatelessWidget {
@@ -19,16 +20,7 @@ class DeleteProfileDialog extends StatelessWidget {
1920
return Center(
2021
child: SingleChildScrollView(
2122
child: Center(
22-
child: AlertDialog(
23-
surfaceTintColor: AppSettings.isDarkMode
24-
? TaskWarriorColors.kdialogBackGroundColor
25-
: TaskWarriorColors.kLightDialogBackGroundColor,
26-
shadowColor: AppSettings.isDarkMode
27-
? TaskWarriorColors.kdialogBackGroundColor
28-
: TaskWarriorColors.kLightDialogBackGroundColor,
29-
backgroundColor: AppSettings.isDarkMode
30-
? TaskWarriorColors.kdialogBackGroundColor
31-
: TaskWarriorColors.kLightDialogBackGroundColor,
23+
child: Utils.showAlertDialog(
3224
scrollable: true,
3325
title: Text(
3426
'Delete Profile?',

lib/widgets/profilefunctions/renameprofiledialog.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:taskwarrior/config/app_settings.dart';
33
import 'package:taskwarrior/config/taskwarriorcolors.dart';
4+
import 'package:taskwarrior/utility/utilities.dart';
45

56
import 'package:taskwarrior/widgets/taskdetails.dart';
67

@@ -22,16 +23,7 @@ class RenameProfileDialog extends StatelessWidget {
2223

2324
return SingleChildScrollView(
2425
child: Center(
25-
child: AlertDialog(
26-
surfaceTintColor: AppSettings.isDarkMode
27-
? TaskWarriorColors.kdialogBackGroundColor
28-
: TaskWarriorColors.kLightDialogBackGroundColor,
29-
shadowColor: AppSettings.isDarkMode
30-
? TaskWarriorColors.kdialogBackGroundColor
31-
: TaskWarriorColors.kLightDialogBackGroundColor,
32-
backgroundColor: AppSettings.isDarkMode
33-
? TaskWarriorColors.kdialogBackGroundColor
34-
: TaskWarriorColors.kLightDialogBackGroundColor,
26+
child: Utils.showAlertDialog(
3527
scrollable: true,
3628
title: Text(
3729
'Rename Alias',

lib/widgets/taskdetails/description_widget.dart

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:loggy/loggy.dart';
66
import 'package:taskwarrior/config/app_settings.dart';
77
import 'package:taskwarrior/config/taskwarriorcolors.dart';
88
import 'package:taskwarrior/config/taskwarriorfonts.dart';
9+
import 'package:taskwarrior/utility/utilities.dart';
910

1011
class DescriptionWidget extends StatelessWidget {
1112
const DescriptionWidget(
@@ -66,16 +67,7 @@ class DescriptionWidget extends StatelessWidget {
6667
);
6768
showDialog(
6869
context: context,
69-
builder: (context) => AlertDialog(
70-
surfaceTintColor: AppSettings.isDarkMode
71-
? TaskWarriorColors.kdialogBackGroundColor
72-
: TaskWarriorColors.kLightDialogBackGroundColor,
73-
shadowColor: AppSettings.isDarkMode
74-
? TaskWarriorColors.kdialogBackGroundColor
75-
: TaskWarriorColors.kLightDialogBackGroundColor,
76-
backgroundColor: AppSettings.isDarkMode
77-
? TaskWarriorColors.kdialogBackGroundColor
78-
: TaskWarriorColors.kLightDialogBackGroundColor,
70+
builder: (context) => Utils.showAlertDialog(
7971
scrollable: true,
8072
title: Text(
8173
'Edit description',
@@ -195,16 +187,7 @@ class ProjectWidget extends StatelessWidget {
195187
);
196188
showDialog(
197189
context: context,
198-
builder: (context) => AlertDialog(
199-
surfaceTintColor: AppSettings.isDarkMode
200-
? TaskWarriorColors.kdialogBackGroundColor
201-
: TaskWarriorColors.kLightDialogBackGroundColor,
202-
shadowColor: AppSettings.isDarkMode
203-
? TaskWarriorColors.kdialogBackGroundColor
204-
: TaskWarriorColors.kLightDialogBackGroundColor,
205-
backgroundColor: AppSettings.isDarkMode
206-
? TaskWarriorColors.kdialogBackGroundColor
207-
: TaskWarriorColors.kLightDialogBackGroundColor,
190+
builder: (context) => Utils.showAlertDialog(
208191
scrollable: true,
209192
title: Text(
210193
'Edit project',

0 commit comments

Comments
 (0)