-
Notifications
You must be signed in to change notification settings - Fork 56
/
toast.dart
143 lines (140 loc) · 5.38 KB
/
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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import 'package:flutter/material.dart';
import 'package:flutter_learn/utils/oktoast.dart';
import 'package:flutter_learn/utils/toast.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:oktoast/oktoast.dart';
class ToastPage extends StatefulWidget {
ToastPage(this.title, {Key key}) : super(key: key);
final String title;
@override
_ToastPageState createState() => _ToastPageState();
}
class _ToastPageState extends State<ToastPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
padding: const EdgeInsets.all(20),
child: ListView(
scrollDirection: Axis.vertical, // 水平listView
children: <Widget>[
Text("使用原生的toast"),
ButtonBar(
alignment:
MainAxisAlignment.start, //布局方向,默认MainAxisAlignment.end
mainAxisSize: MainAxisSize.max, //主轴大小,默认MainAxisSize.max
children: <Widget>[
// Button集合
RaisedButton(
child: Text('普通toast'),
onPressed: () => {XToast.toast("这是一个普通的Toast")},
),
RaisedButton(
child: Text('警告toast'),
onPressed: () => {XToast.waring("这是一个警告Toast")},
),
],
),
ButtonBar(
alignment:
MainAxisAlignment.start, //布局方向,默认MainAxisAlignment.end
mainAxisSize: MainAxisSize.max, //主轴大小,默认MainAxisSize.max
children: <Widget>[
// Button集合
RaisedButton(
child: Text('错误toast'),
onPressed: () => {
XToast.error("这是一个错误Toast", length: Toast.LENGTH_LONG)
},
),
RaisedButton(
child: Text('成功toast'),
onPressed: () => {XToast.success("这是一个成功Toast")},
),
],
),
Text("使用非原生的toast"),
ButtonBar(
alignment:
MainAxisAlignment.start, //布局方向,默认MainAxisAlignment.end
mainAxisSize: MainAxisSize.max, //主轴大小,默认MainAxisSize.max
children: <Widget>[
// Button集合
RaisedButton(
child: Text('普通toast'),
onPressed: () => {ToastUtils.toast("这是一个普通的Toast")},
),
RaisedButton(
child: Text('警告toast'),
onPressed: () => {ToastUtils.waring("这是一个警告Toast")},
),
],
),
ButtonBar(
alignment:
MainAxisAlignment.start, //布局方向,默认MainAxisAlignment.end
mainAxisSize: MainAxisSize.max, //主轴大小,默认MainAxisSize.max
children: <Widget>[
// Button集合
RaisedButton(
child: Text('错误toast'),
onPressed: () => {
ToastUtils.error("这是一个错误Toast",
duration: Duration(seconds: 5))
},
),
RaisedButton(
child: Text('成功toast'),
onPressed: () => {ToastUtils.success("这是一个成功Toast")},
),
],
),
Text("自定义toast"),
ButtonBar(
alignment:
MainAxisAlignment.start, //布局方向,默认MainAxisAlignment.end
mainAxisSize: MainAxisSize.max, //主轴大小,默认MainAxisSize.max
children: <Widget>[
// Button集合
RaisedButton(
child: Text('自定义toast'),
onPressed: () {
showCustomToast('这是自定义的toast~~');
}
),
],
),
],
)));
}
showCustomToast(String msg) {
// 3.2 use showToastWidget method
Widget widget = Container(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 5),
decoration: BoxDecoration(
color: DEFAULT_TOAST_COLOR,
borderRadius: BorderRadius.circular(10),
),
child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(30.0),
child: Container(
child: Icon(
Icons.warning,
size: 30.0,
color: Colors.white,
),
),
),
SizedBox(width: 5),
Text(msg)
]));
showToastWidget(
widget,
duration: Duration(seconds: 3),
);
}
}