-
-
Notifications
You must be signed in to change notification settings - Fork 647
Expand file tree
/
Copy pathgf_alert.dart
More file actions
273 lines (243 loc) · 9.38 KB
/
gf_alert.dart
File metadata and controls
273 lines (243 loc) · 9.38 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import 'package:flutter/material.dart';
import 'package:getwidget/getwidget.dart';
class GFAlert extends StatefulWidget {
/// Alert has to be wrap inside the body like [GFFloatingWidget]. See [GFFloatingWidget]
const GFAlert({
Key? key,
this.title,
this.titleTextStyle = const TextStyle(
color: Colors.black87,
fontSize: 20,
fontWeight: FontWeight.w700,
),
this.titleAlignment,
this.subtitle,
this.subtitleTextStyle = const TextStyle(
color: Colors.black87,
fontSize: 17,
fontWeight: FontWeight.w400,
),
this.subtitleAlignment,
this.bottomBar,
this.bottomBarAlignment,
this.content,
this.contentAlignment,
this.backgroundColor,
this.width,
this.type = GFAlertType.rounded,
this.alignment,
this.padding,
this.shadow,
this.borderRadius,
this.okButtonText,
this.cancelButtonText,
this.okButtonTextStyle = const TextStyle(
fontSize: 18,
color: Colors.lightBlue,
),
this.cancelButtonTextStyle = const TextStyle(
fontSize: 18,
color: Colors.lightBlue,
),
this.onTapCancel,
this.onTapOk,
}) : super(key: key);
/// title of type [String] used to describe the title of the [GFAlert]
final String? title;
///type of [TextStyle] to change the style of the title
final TextStyle titleTextStyle;
/// type of [Alignment] used to align the title text inside the [GFAlert]
final Alignment? titleAlignment;
/// title of type [String] used to describe the subtitle of the [GFAlert]
final String? subtitle;
///type of [TextStyle] to change the style of the subtitle
final TextStyle subtitleTextStyle;
/// type of [Alignment] used to align the subtitle text inside the [GFAlert]
final Alignment? subtitleAlignment;
///ContentChild of type [Widget] can be used to show a widget with contents in the [GFAlert]
final Widget? content;
/// type of [Alignment] used to align the content widget [GFAlert]
final Alignment? contentAlignment;
/// bottomBar of type [Widget] can be used to show a widget at the bottom of subtitle.
final Widget? bottomBar;
/// type of [Alignment] used to align the bottom widget [GFAlert]
final Alignment? bottomBarAlignment;
/// type of [List] of type [BoxShadow] to give shadow to [GFAlert]
final List<BoxShadow>? shadow;
/// type of [EdgeInsetsGeometry] to give padding inside [GFAlert]
final EdgeInsetsGeometry? padding;
/// type of [double] to give circular radius to [GFAlert]
final double? borderRadius;
///pass color of type [Color] or [GFColors] for background of [GFAlert]
final Color? backgroundColor;
/// width of type [double] used to control the width of the [GFAlert]
final double? width;
///type of [GFAlertType] which takes the type ie, basic, rounded and fullWidth for the [GFAlert]
final GFAlertType type;
/// type of [Alignment] used to align the [GFAlert]
final Alignment? alignment;
/// type of [String] used to replace the text of cancel button in [GFAlert]
final String? cancelButtonText;
///type of [TextStyle] to change the style of the cancel button text
final TextStyle cancelButtonTextStyle;
///type of [TextStyle] to change the style of the ok button text
final TextStyle okButtonTextStyle;
/// type of [String] used to replace the text of ok button in [GFAlert]
final String? okButtonText;
/// type of [Function] used for tap on ok button in [GFAlert]
final void Function()? onTapOk;
/// type of [Function] used for tap on cancel button in [GFAlert]
final void Function()? onTapCancel;
@override
_GFAlertState createState() => _GFAlertState();
}
class _GFAlertState extends State<GFAlert> with TickerProviderStateMixin {
late AnimationController animationController;
late Animation<double> animation;
@override
void initState() {
animationController = AnimationController(
duration: const Duration(milliseconds: 300),
vsync: this,
);
animation = CurvedAnimation(
parent: animationController,
curve: Curves.fastOutSlowIn,
);
animationController.forward();
super.initState();
}
@override
void dispose() {
animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => FadeTransition(
opacity: animation,
child: Column(
children: <Widget>[
Align(
alignment: widget.alignment ?? Alignment.center,
child: Container(
width: widget.type == GFAlertType.fullWidth
? MediaQuery.of(context).size.width
: widget.width ?? MediaQuery.of(context).size.width * 0.885,
constraints: const BoxConstraints(
minHeight: 50,
),
margin: widget.type == GFAlertType.fullWidth
? const EdgeInsets.only(
left: 0,
right: 0,
)
: const EdgeInsets.only(
left: 20,
right: 20,
top: 20,
bottom: 20,
),
padding: widget.padding ??
const EdgeInsets.only(
left: 20,
right: 20,
top: 20,
bottom: 10,
),
decoration: BoxDecoration(
borderRadius: widget.type == GFAlertType.basic
? BorderRadius.circular(3)
: widget.type == GFAlertType.rounded
? BorderRadius.circular(
widget.borderRadius ?? 10,
)
: BorderRadius.zero,
color: widget.backgroundColor ?? GFColors.WHITE,
boxShadow: widget.shadow ??
[
BoxShadow(
color: Colors.black87.withValues(alpha: 0.1),
offset: const Offset(0, 1),
blurRadius: 10,
spreadRadius: 2,
)
],
),
child: ClipRRect(
borderRadius: widget.type == GFAlertType.rounded
? BorderRadius.circular(
widget.borderRadius ?? 10,
)
: BorderRadius.zero,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
if (widget.title != null) ...[
Align(
alignment: widget.titleAlignment ?? Alignment.topLeft,
child: Text(
widget.title!,
style: widget.titleTextStyle,
),
),
const SizedBox(
height: 10,
),
],
if (widget.subtitle != null) ...[
Align(
alignment:
widget.subtitleAlignment ?? Alignment.topLeft,
child: Text(
widget.subtitle!,
style: widget.subtitleTextStyle,
)),
const SizedBox(
height: 10,
),
],
if (widget.content != null) ...[
Align(
alignment:
widget.contentAlignment ?? Alignment.centerLeft,
child: widget.content,
),
const SizedBox(
height: 10,
),
],
Align(
alignment:
widget.bottomBarAlignment ?? Alignment.bottomRight,
child: widget.bottomBar ??
Container(
padding: const EdgeInsets.only(top: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
child: Text(
widget.cancelButtonText ?? 'CANCEL',
style: widget.cancelButtonTextStyle,
),
onPressed: widget.onTapCancel,
),
TextButton(
child: Text(
widget.okButtonText ?? 'OK',
style: widget.okButtonTextStyle,
),
onPressed: widget.onTapOk),
],
),
),
),
],
),
),
),
),
],
),
);
}