A package for flutter to use alert and toast within one line code.
Add
easy_alert:
to your pubspec.yaml, and run flutter packages get
in your project root directory.
- alert
- ios style alert
- confirm
- ios style confirm
- toast
- customize alert dialog
- customize toast
- support bottom sheet.
- support input
- support pick and select
void main() => runApp(new AlertProvider(
child: new YourApp(),
config: new AlertConfig(
ok: "OK text for `ok` button in AlertDialog",
cancel: "CANCEL text for `cancel` button in AlertDialog"),
));
Alert.alert(context, title: "Hello", content: "this is a alert")
.then((_) => Alert.toast(context, "You just click ok"));
Alert.confirm(context, title: "Hello", content: "this is a alert")
.then((int ret) =>
Alert.toast(context, ret == Alert.OK ? "ok" : "cancel"));
Alert.toast(context,"Very long toast",position: ToastPosition.bottom, duration: ToastDuration.long);
try {
int index = await Alert.pick(context,
values: widget.values, index: widget.index);
...have selected
} catch (e) {
... cancel select
}
try {
String ret = await Alert.select(context,
options: [
Option('A', 'a'),
Option('B', 'b'),
Option('C', 'c'),
],
value: 'a');
Alert.toast(context, "You just pick $ret");
} catch (e) {
Alert.toast(context, "Canceled",
position: ToastPosition.center);
}