/
toast_page.dart
168 lines (161 loc) · 6.23 KB
/
toast_page.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import 'package:flutter/material.dart';
import 'package:flui/flui.dart';
import 'package:example/util.dart';
class ToastPage extends StatefulWidget {
static const String routeName = '/toast';
@override
State<ToastPage> createState() => _ToastPageState();
}
class _ToastPageState extends State<ToastPage> {
FLToastStyle _toastStyle = FLToastStyle.dark;
FLToastPosition _toastPosition = FLToastPosition.center;
Function _hideCustomToast;
@override
void dispose() {
super.dispose();
Util.eventBus.fire('reset');
}
@override
Widget build(BuildContext context) {
if (_hideCustomToast != null) {
_hideCustomToast();
_hideCustomToast = null;
}
final bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
final Widget inset = SizedBox(height: 15);
final TextStyle textStyle = isDarkMode
? TextStyle(fontSize: 15)
: TextStyle(fontSize: 15, color: Theme.of(context).primaryColor);
return Scaffold(
appBar: AppBar(
title: FLAppBarTitle(
title: 'Toast',
),
centerTitle: true,
),
body: Container(
width: double.infinity,
height: double.infinity,
child: ListView(
shrinkWrap: true,
children: <Widget>[
Column(
children: <Widget>[
inset,
SizedBox(
width: 220,
child: OutlineButton(
child: Text('Text Toast', style: textStyle),
onPressed: () => FLToast.text(text: 'Here is text'),
),
),
inset,
SizedBox(
width: 220,
child: OutlineButton(
child: Text('Loading Toast', style: textStyle),
onPressed: () {
var dismiss = FLToast.loading(text: 'Loading...');
Future.delayed(Duration(seconds: 2), () {
dismiss();
});
},
),
),
inset,
SizedBox(
width: 220,
child: OutlineButton(
child: Text('Success Toast', style: textStyle),
onPressed: () => FLToast.success(text: 'Fetch success'),
),
),
inset,
SizedBox(
width: 220,
child: OutlineButton(
child: Text('Info Toast', style: textStyle),
onPressed: () => FLToast.info(text: 'Some info'),
),
),
inset,
SizedBox(
width: 220,
child: OutlineButton(
child: Text('Error Toast', style: textStyle),
onPressed: () =>
FLToast.error(text: 'Something was wrong'),
),
),
inset,
GestureDetector(
onTapDown: (TapDownDetails details) {
final Widget mic = Container(
padding: EdgeInsets.all(15),
child: Image.asset('assets/record.gif', scale: 2));
_hideCustomToast = FLToast.show(
text: 'Swipe up to cancel sending',
contentBuilder: (context) => mic);
},
onLongPressEnd: (LongPressEndDetails details) {
if (_hideCustomToast != null) {
_hideCustomToast();
_hideCustomToast = null;
}
},
child: Container(
width: 220,
height: 35,
decoration: BoxDecoration(
border: Border.all(color: Colors.grey.withAlpha(100)),
borderRadius: BorderRadius.all(Radius.circular(2)),
),
child: Center(
child: Text('Custom Toast', style: textStyle),
),
),
),
inset,
inset,
SizedBox(
width: 220,
child: OutlineButton(
child: Text('Position Top', style: textStyle),
onPressed: () => setState(() {
_toastPosition = FLToastPosition.top;
Util.eventBus.fire(FLToastDefaults(
style: _toastStyle, position: _toastPosition));
}),
),
),
inset,
SizedBox(
width: 220,
child: OutlineButton(
child: Text('Position Center', style: textStyle),
onPressed: () => setState(() {
_toastPosition = FLToastPosition.center;
Util.eventBus.fire(FLToastDefaults(
style: _toastStyle, position: _toastPosition));
}),
),
),
inset,
SizedBox(
width: 220,
child: OutlineButton(
child: Text('Position Bottom', style: textStyle),
onPressed: () => setState(() {
_toastPosition = FLToastPosition.bottom;
Util.eventBus.fire(FLToastDefaults(
style: _toastStyle, position: _toastPosition));
}),
),
),
inset,
],
)
],
)));
}
}