-
Notifications
You must be signed in to change notification settings - Fork 73
/
rflutter_alert.dart
199 lines (188 loc) · 5.53 KB
/
rflutter_alert.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import 'package:flutter/material.dart';
import 'package:rflutter_alert/rflutter_alert.dart';
class MyRflutterAlert extends StatelessWidget {
const MyRflutterAlert({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Rflutter Alert')),
body: const PopupDialog(),
);
}
}
class PopupDialog extends StatelessWidget {
const PopupDialog({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
child: const Text('Basic Alert'),
onPressed: () => _onBasicAlertPressed(context),
),
ElevatedButton(
child: const Text('Alert with Button'),
onPressed: () => _onAlertButtonPressed(context),
),
ElevatedButton(
child: const Text('Alert with Buttons'),
onPressed: () => _onAlertButtonsPressed(context),
),
ElevatedButton(
child: const Text('Alert with Style'),
onPressed: () => _onAlertWithStylePressed(context),
),
ElevatedButton(
child: const Text('Alert with Custom Image'),
onPressed: () => _onAlertWithCustomImagePressed(context),
),
ElevatedButton(
child: const Text('Alert with Custom Content'),
onPressed: () => _onAlertWithCustomContentPressed(context),
),
],
),
);
}
// The easiest way for creating RFlutter Alert
_onBasicAlertPressed(context) {
Alert(
context: context,
title: "RFLUTTER ALERT",
desc: "Flutter is more awesome with RFlutter Alert.")
.show();
}
// Alert with single button.
_onAlertButtonPressed(context) {
Alert(
context: context,
type: AlertType.error,
title: "RFLUTTER ALERT",
desc: "Flutter is more awesome with RFlutter Alert.",
buttons: [
DialogButton(
onPressed: () => Navigator.pop(context),
width: 120,
child: const Text(
"COOL",
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
],
).show();
}
// Alert with multiple and custom buttons
_onAlertButtonsPressed(context) {
Alert(
context: context,
type: AlertType.warning,
title: "RFLUTTER ALERT",
desc: "Flutter is more awesome with RFlutter Alert.",
buttons: [
DialogButton(
onPressed: () => Navigator.pop(context),
color: const Color.fromRGBO(0, 179, 134, 1.0),
child: const Text(
"FLAT",
style: TextStyle(color: Colors.white, fontSize: 19),
),
),
DialogButton(
onPressed: () => Navigator.pop(context),
gradient: const LinearGradient(
colors: [
Color.fromRGBO(116, 116, 191, 1.0),
Color.fromRGBO(52, 138, 199, 1.0),
],
),
child: const Text(
"GRADIENT",
style: TextStyle(color: Colors.white, fontSize: 19),
),
)
],
).show();
}
// Advanced using of alerts
_onAlertWithStylePressed(context) {
// Reusable alert style
var alertStyle = AlertStyle(
animationType: AnimationType.fromTop,
isCloseButton: false,
isOverlayTapDismiss: false,
descStyle: const TextStyle(fontWeight: FontWeight.bold),
animationDuration: const Duration(milliseconds: 400),
alertBorder: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0.0),
side: const BorderSide(
color: Colors.grey,
),
),
titleStyle: const TextStyle(
color: Colors.red,
),
);
// Alert dialog using custom alert style
Alert(
context: context,
style: alertStyle,
type: AlertType.info,
title: "RFLUTTER ALERT",
desc: "Flutter is more awesome with RFlutter Alert.",
buttons: [
DialogButton(
onPressed: () => Navigator.pop(context),
color: const Color.fromRGBO(0, 179, 134, 1.0),
radius: BorderRadius.circular(0.0),
child: const Text(
"COOL",
style: TextStyle(color: Colors.white, fontSize: 20),
),
),
],
).show();
}
// Alert custom images
_onAlertWithCustomImagePressed(context) {
Alert(
context: context,
title: "RFLUTTER ALERT",
desc: "Flutter is more awesome with RFlutter Alert.",
image: Image.asset("assets/images/rflutter_alert/success.png"),
).show();
}
// Alert custom content
_onAlertWithCustomContentPressed(context) {
Alert(
context: context,
title: "LOGIN",
content: const Column(
children: [
TextField(
decoration: InputDecoration(
icon: Icon(Icons.account_circle),
labelText: 'Username',
),
),
TextField(
obscureText: true,
decoration: InputDecoration(
icon: Icon(Icons.lock),
labelText: 'Password',
),
),
],
),
buttons: [
DialogButton(
onPressed: () => Navigator.pop(context),
child: const Text(
"LOGIN",
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
]).show();
}
}