-
Notifications
You must be signed in to change notification settings - Fork 38
/
Utils.dart
127 lines (115 loc) Β· 3.68 KB
/
Utils.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import 'package:flutter/material.dart';
import 'package:todo_app/AppColors.dart';
import 'package:todo_app/Localization.dart';
class Utils {
static bool isLessDay(DateTime standard, DateTime target) {
if (standard.year > target.year) {
return true;
} else if (standard.year == target.year && standard.month > target.month) {
return true;
} else if (standard.year == target.year && standard.month == target.month && standard.day > target.day) {
return true;
} else {
return false;
}
}
static bool isSameDay(DateTime d1, DateTime d2) {
return d1.year == d2.year && d1.month == d2.month && d1.day == d2.day;
}
static bool isMoreDay(DateTime standard, DateTime target) {
if (standard.year < target.year) {
return true;
} else if (standard.year == target.year && standard.month < target.month) {
return true;
} else if (standard.year == target.year && standard.month == target.month && standard.day < target.day) {
return true;
} else {
return false;
}
}
static List<DateTime> getDatesInWeek(DateTime date) {
final List<DateTime> datesInWeek = [];
final mondayOfWeek = date.subtract(Duration(days: date.weekday - DateTime.monday));
for (int i = 0; i < 7; i++) {
datesInWeek.add(mondayOfWeek.add(Duration(days: i)));
}
return datesInWeek;
}
static Future<void> showBottomSheet(ScaffoldState scaffoldState,
void Function(BuildContext context) builder, {
void Function() onClosed,
}) async {
await scaffoldState.showBottomSheet(builder).closed;
if (onClosed != null) {
onClosed();
}
}
static void showSnackBar(ScaffoldState scaffoldState, String text, Duration duration) {
scaffoldState.removeCurrentSnackBar();
scaffoldState.showSnackBar(SnackBar(
content: Text(text),
duration: duration,
));
}
static Future<T> showAppDialog<T>(BuildContext context,
String title, String body,
void Function() onCancelClicked, void Function() onOkClicked) async {
return showDialog<T>(
context: context,
barrierDismissible: true,
builder: (context) {
return AlertDialog(
title: Text(
title,
style: TextStyle(
color: AppColors.TEXT_BLACK,
fontSize: 20,
),
),
content: Text(
body,
style: TextStyle(
color: AppColors.TEXT_BLACK_LIGHT,
fontSize: 16,
),
),
actions: <Widget>[
FlatButton(
child: Text(
AppLocalizations.of(context).cancel,
style: TextStyle(
color: AppColors.TEXT_BLACK,
fontSize: 14,
),
),
onPressed: () {
Navigator.pop(context);
if (onCancelClicked != null) {
onCancelClicked();
}
},
),
FlatButton(
child: Text(
AppLocalizations.of(context).ok,
style: TextStyle(
color: AppColors.PRIMARY,
fontSize: 14,
),
),
onPressed: () {
Navigator.pop(context);
if (onOkClicked != null) {
onOkClicked();
}
},
)
],
);
},
);
}
static String toLastUpdatedFormat(DateTime date) {
return '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')} ${date.hour.toString().padLeft(2, '0')}:${date.minute.toString().padLeft(2, '0')}';
}
}