-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflutter_toast.dart
101 lines (93 loc) · 2.96 KB
/
flutter_toast.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
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
enum ToastStates { success, error, warning }
class MessageUtils {
static Color chooseToastColor(ToastStates state) {
Color color;
switch (state) {
case ToastStates.success:
color = Colors.green;
break;
case ToastStates.error:
color = Colors.red;
break;
case ToastStates.warning:
color = Colors.amber;
break;
}
return color;
}
static void showToastApp(
{required String msg,
Duration? duration,
required ToastStates state}) =>
Fluttertoast.showToast(
msg: msg,
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 5,
backgroundColor: chooseToastColor(state),
textColor: Colors.white,
fontSize: 16,
);
static void hintSnackBar(BuildContext context,
{required String msg, Duration? duration}) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(msg),
backgroundColor: Colors.grey,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
duration: duration ?? const Duration(seconds: 3),
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
),
);
}
static void loadingSnackBar(BuildContext context,
{required String msg, Duration? duration}) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(msg),
backgroundColor: Colors.tealAccent,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
duration: duration ?? const Duration(seconds: 3),
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
),
);
}
static void successSnackBar(BuildContext context,
{required String msg, Duration? duration}) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(msg),
backgroundColor: Colors.green,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
duration: duration ?? const Duration(seconds: 3),
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
),
);
}
static void errorSnackBar(BuildContext context,
{required String msg, Duration? duration}) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(msg),
backgroundColor: Colors.red,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
duration: duration ?? const Duration(seconds: 3),
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
),
);
}
}