Skip to content

Commit d546d3b

Browse files
committed
custom content and custom image features added
1 parent 1d112e4 commit d546d3b

File tree

5 files changed

+123
-74
lines changed

5 files changed

+123
-74
lines changed

example/assets/success.png

9.2 KB
Loading

example/lib/main.dart

+55-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,15 @@ class PopupDialog extends StatelessWidget {
4141
RaisedButton(
4242
child: Text('Alert with Style'),
4343
onPressed: () => _onAlertWithStylePressed(context),
44-
)
44+
),
45+
RaisedButton(
46+
child: Text('Alert with Custom Image'),
47+
onPressed: () => _onAlertWithCustomImagePressed(context),
48+
),
49+
RaisedButton(
50+
child: Text('Alert with Custom Content'),
51+
onPressed: () => _onAlertWithCustomContentPressed(context),
52+
),
4553
],
4654
),
4755
),
@@ -51,10 +59,10 @@ class PopupDialog extends StatelessWidget {
5159
// The easiest way for creating RFlutter Alert
5260
_onBasicAlertPressed(context) {
5361
Alert(
54-
context: context,
55-
title: "RFLUTTER ALERT",
56-
desc: "Flutter is better with RFlutter Alert."
57-
).show();
62+
context: context,
63+
title: "RFLUTTER ALERT",
64+
desc: "Flutter is better with RFlutter Alert.")
65+
.show();
5866
}
5967

6068
// Alert with single button.
@@ -110,11 +118,10 @@ class PopupDialog extends StatelessWidget {
110118

111119
// Advanced using of alerts
112120
_onAlertWithStylePressed(context) {
113-
114121
// Reusable alert style
115122
var alertStyle = AlertStyle(
116123
animationType: AnimationType.fromTop,
117-
isCloseButton: false,
124+
isCloseButton: true,
118125
isOverlayTapDismiss: false,
119126
descStyle: TextStyle(fontWeight: FontWeight.bold),
120127
animationDuration: Duration(milliseconds: 400),
@@ -149,4 +156,45 @@ class PopupDialog extends StatelessWidget {
149156
],
150157
).show();
151158
}
159+
160+
_onAlertWithCustomImagePressed(context) {
161+
Alert(
162+
context: context,
163+
title: "RFLUTTER ALERT",
164+
desc: "Flutter is better with RFlutter Alert.",
165+
image: Image.asset("assets/success.png"),
166+
).show();
167+
}
168+
169+
_onAlertWithCustomContentPressed(context) {
170+
Alert(
171+
context: context,
172+
title: "LOGIN",
173+
content: Column(
174+
children: <Widget>[
175+
TextField(
176+
decoration: InputDecoration(
177+
icon: Icon(Icons.account_circle),
178+
labelText: 'Username',
179+
),
180+
),
181+
TextField(
182+
obscureText: true,
183+
decoration: InputDecoration(
184+
icon: Icon(Icons.lock),
185+
labelText: 'Password',
186+
),
187+
),
188+
],
189+
),
190+
buttons: [
191+
DialogButton(
192+
onPressed: () => Navigator.pop(context),
193+
child: Text(
194+
"LOGIN",
195+
style: TextStyle(color: Colors.white, fontSize: 20),
196+
),
197+
)
198+
]).show();
199+
}
152200
}

example/pubspec.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ dev_dependencies:
1717
sdk: flutter
1818

1919
flutter:
20-
uses-material-design: true
20+
uses-material-design: true
21+
assets:
22+
- assets/

lib/src/alert.dart

+64-65
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Alert {
2323
final Image image;
2424
final String title;
2525
final String desc;
26+
final Widget content;
2627
final List<DialogButton> buttons;
2728

2829
/// Alert constructor
@@ -35,6 +36,7 @@ class Alert {
3536
this.image,
3637
@required this.title,
3738
this.desc,
39+
this.content,
3840
this.buttons,
3941
});
4042

@@ -60,7 +62,7 @@ class Alert {
6062
);
6163
}
6264

63-
// Will be added in next version.
65+
// Will be added in next version.
6466
// void dismiss() {
6567
// Navigator.pop(context);
6668
// }
@@ -69,46 +71,41 @@ class Alert {
6971
Widget _buildDialog() {
7072
return AlertDialog(
7173
shape: style.alertBorder ?? _defaultShape(),
74+
titlePadding: EdgeInsets.all(0.0),
7275
title: Container(
7376
child: Center(
7477
child: Column(
7578
mainAxisAlignment: MainAxisAlignment.center,
7679
children: <Widget>[
77-
Row(
78-
mainAxisAlignment: MainAxisAlignment.spaceBetween,
79-
mainAxisSize: MainAxisSize.max,
80-
crossAxisAlignment: CrossAxisAlignment.start,
81-
children: <Widget>[
82-
SizedBox(
83-
height: 20,
84-
width: 20,
85-
),
86-
_getImage(),
87-
style.isCloseButton
88-
? _getCloseButton()
89-
: SizedBox(
90-
height: 20,
91-
width: 20,
92-
),
93-
],
94-
),
95-
SizedBox(
96-
height: 15,
97-
),
98-
Text(
99-
title,
100-
style: style.titleStyle,
101-
textAlign: TextAlign.center,
102-
),
103-
SizedBox(
104-
height: desc == null ? 0 : 10,
105-
),
106-
desc == null ? Container() :
107-
Text(
108-
desc,
109-
style: style.descStyle,
110-
textAlign: TextAlign.center,
111-
),
80+
_getCloseButton(),
81+
Padding(
82+
padding: EdgeInsets.fromLTRB(
83+
20, (style.isCloseButton ? 0 : 20), 20, 0),
84+
child: Column(
85+
children: <Widget>[
86+
_getImage(),
87+
SizedBox(
88+
height: 15,
89+
),
90+
Text(
91+
title,
92+
style: style.titleStyle,
93+
textAlign: TextAlign.center,
94+
),
95+
SizedBox(
96+
height: desc == null ? 5 : 10,
97+
),
98+
desc == null
99+
? Container()
100+
: Text(
101+
desc,
102+
style: style.descStyle,
103+
textAlign: TextAlign.center,
104+
),
105+
content == null ? Container() : content,
106+
],
107+
),
108+
)
112109
],
113110
),
114111
),
@@ -133,6 +130,36 @@ class Alert {
133130
);
134131
}
135132

133+
// Returns the close button on the top right
134+
Widget _getCloseButton() {
135+
return style.isCloseButton
136+
? Padding(
137+
padding: const EdgeInsets.fromLTRB(0, 10, 10, 0),
138+
child: Container(
139+
alignment: FractionalOffset.topRight,
140+
child: Container(
141+
width: 20,
142+
height: 20,
143+
decoration: BoxDecoration(
144+
image: DecorationImage(
145+
image: AssetImage(
146+
'$kImagePath/close.png',
147+
package: 'rflutter_alert',
148+
),
149+
),
150+
),
151+
child: Material(
152+
color: Colors.transparent,
153+
child: InkWell(
154+
onTap: () => Navigator.pop(context),
155+
),
156+
),
157+
),
158+
),
159+
)
160+
: Container();
161+
}
162+
136163
// Returns defined buttons. Default: Cancel Button
137164
List<Widget> _getButtons() {
138165
List<Widget> expandedButtons = [];
@@ -169,31 +196,9 @@ class Alert {
169196
return expandedButtons;
170197
}
171198

172-
// Returns the close button on the top right
173-
Widget _getCloseButton() {
174-
return Container(
175-
width: 20,
176-
height: 20,
177-
decoration: BoxDecoration(
178-
image: DecorationImage(
179-
image: AssetImage(
180-
'$kImagePath/close.png',
181-
package: 'rflutter_alert',
182-
),
183-
),
184-
),
185-
child: Material(
186-
color: Colors.transparent,
187-
child: InkWell(
188-
onTap: () => Navigator.pop(context),
189-
),
190-
),
191-
);
192-
}
193-
194199
// Returns alert image for icon
195200
Widget _getImage() {
196-
Widget response = image;
201+
Widget response = image ?? Container();
197202
switch (type) {
198203
case AlertType.success:
199204
response = Image.asset(
@@ -222,12 +227,6 @@ class Alert {
222227
case AlertType.none:
223228
response = Container();
224229
break;
225-
default:
226-
response = Image.asset(
227-
'$kImagePath/icon_success.png',
228-
package: 'rflutter_alert',
229-
);
230-
break;
231230
}
232231
return response;
233232
}

lib/src/alert_style.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AlertStyle {
3535
this.animationType = AnimationType.fromBottom,
3636
this.animationDuration = const Duration(milliseconds: 200),
3737
this.alertBorder,
38-
this.isCloseButton = true,
38+
this.isCloseButton = false,
3939
this.isOverlayTapDismiss = true,
4040
this.overlayColor = Colors.black87,
4141
this.titleStyle = const TextStyle(

0 commit comments

Comments
 (0)