-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathalert_service.dart
59 lines (54 loc) · 1.43 KB
/
alert_service.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
import 'package:flushbar/flushbar.dart';
import 'package:flutter/material.dart';
enum AlertType { success, error, warning }
class AlertService {
void showAlert({
@required String message,
@required AlertType type,
@required BuildContext context,
}) {
Flushbar(
title: _chooseTitle(type),
message: message,
icon: Icon(
_chooseIcon(type),
size: 28.0,
color: Colors.white,
),
flushbarPosition: FlushbarPosition.TOP,
flushbarStyle: FlushbarStyle.GROUNDED,
reverseAnimationCurve: Curves.decelerate,
forwardAnimationCurve: Curves.elasticOut,
backgroundColor: _chooseColor(type),
isDismissible: false,
duration: Duration(seconds: 3),
)..show(context);
}
Color _chooseColor(AlertType type) {
if (type == AlertType.success) {
return Colors.green;
} else if (type == AlertType.error) {
return Colors.red;
} else {
return Colors.orange;
}
}
String _chooseTitle(AlertType type) {
if (type == AlertType.success) {
return "Success!!!";
} else if (type == AlertType.error) {
return "Error!!!";
} else {
return "Warning!!!";
}
}
IconData _chooseIcon(AlertType type) {
if (type == AlertType.success) {
return Icons.check_circle_outline;
} else if (type == AlertType.error) {
return Icons.error_outline;
} else {
return Icons.info_outline;
}
}
}