pubspec.yaml
sweetalert: any
main.dart
import 'package:flutter/material.dart';
import 'package:sweetalert/sweetalert.dart';
void main() {
String title = "Sweet Alert";
Color bgColor = Colors.blue;
Color fgColor = Colors.white;
IconData icLogo = Icons.star_border;
runApp(new MaterialApp(
debugShowCheckedModeBanner: false,
title: title,
home: Scaffold(
backgroundColor: fgColor,
appBar: new AppBar(
backgroundColor: bgColor,
leading: Icon(icLogo),
title: Text(title),
),
body: Layout(),
)));
}
class Layout extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Row(
children: <Widget>[
RaisedButton(
child: Text("Basic"),
onPressed: () {
SweetAlert.show(context, title: "Just show a message");
},
),
RaisedButton(
child: Text("Subtitle"),
onPressed: () {
SweetAlert.show(context,
title: "Just show a message",
subtitle: "Sweet alert is pretty");
},
),
RaisedButton(
child: Text("Success"),
onPressed: () {
SweetAlert.show(context,
title: "Just show a message",
subtitle: "Sweet alert is pretty",
style: SweetAlertStyle.success);
},
),
RaisedButton(
child: Text("Error"),
onPressed: () {
SweetAlert.show(context,
title: "Just show a message",
subtitle: "Sweet alert is pretty",
style: SweetAlertStyle.error);
},
),
],
),
Row(
children: <Widget>[
RaisedButton(
child: Text("Confirm"),
onPressed: () {
SweetAlert.show(context,
title: "Just show a message",
subtitle: "Sweet alert is pretty",
style: SweetAlertStyle.confirm,
showCancelButton: true, onPress: (bool isConfirm) {
if (isConfirm) {
SweetAlert.show(context,
style: SweetAlertStyle.success, title: "Success");
// return false to keep dialog
return false;
}
});
},
),
RaisedButton(
child: Text("Confirm 2"),
onPressed: () {
SweetAlert.show(context,
subtitle: "Do you want to delete this message",
style: SweetAlertStyle.confirm,
showCancelButton: true, onPress: (bool isConfirm) {
if (isConfirm) {
SweetAlert.show(context,
subtitle: "Deleting...",
style: SweetAlertStyle.loading);
new Future.delayed(new Duration(seconds: 2), () {
SweetAlert.show(context,
subtitle: "Success!", style: SweetAlertStyle.success);
});
} else {
SweetAlert.show(context,
subtitle: "Canceled!", style: SweetAlertStyle.error);
}
// return false to keep dialog
return false;
});
},
),
],
),
],
);
}
}