toast_utils.dart
2.2 KB
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
import 'package:cp_offline_manage/utils/text_style_ms.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:fluttertoast/fluttertoast.dart';
import '../common/colors.dart';
class ToastUtils {
/// toast
static show([String msg = '加载中', Toast toastLength = Toast.LENGTH_SHORT]) {
Fluttertoast.showToast(
msg: msg,
toastLength: toastLength,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: ColorConfig.color00.withOpacity(0.6),
textColor: ColorConfig.white,
fontSize: 14.0,
);
}
/// 展示弹窗
static showLoading() {
EasyLoading.show(
dismissOnTap: false,
maskType: EasyLoadingMaskType.clear,
);
}
/// 隐藏loading
static hideLoading() {
EasyLoading.dismiss();
}
static final FToast _fToast = FToast();
static initCustomToast(BuildContext context) {
_fToast.init(context);
}
static showWarningCustomToast(String msg) {
Widget toast = Container(
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 21),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: ColorConfig.color00.withOpacity(0.6),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.sentiment_satisfied_sharp, size: 30, color: ColorConfig.themeColor,),
const SizedBox(height: 14),
Text(
msg,
style: TextStyleMs.white_14,
),
],
),
);
_fToast.showToast(
child: toast,
gravity: ToastGravity.CENTER,
toastDuration: const Duration(seconds: 2),
);
}
static showCustomTextToast(String msg) {
Widget toast = Container(
padding: const EdgeInsets.symmetric(horizontal: 47, vertical: 15),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: ColorConfig.color00.withOpacity(0.6),
),
child: Text(
msg,
style: TextStyleMs.white_14,
),
);
_fToast.showToast(
child: toast,
gravity: ToastGravity.CENTER,
toastDuration: const Duration(seconds: 2),
);
}
}