alertDialog function
dynamic
alertDialog({
- @required BuildContext? context,
- @required Widget? title,
- @required Widget? content,
- String? cancelLabel,
- CancelListener? cancelListener,
- String? okLabel,
- OkListener? okListener,
- ThenListener? thenListener,
Implementation
alertDialog({
@required BuildContext? context,
@required Widget? title,
@required Widget? content,
String? cancelLabel,
CancelListener? cancelListener,
String? okLabel,
OkListener? okListener,
ThenListener? thenListener,
}) {
if (context == null) {
return;
}
List<Widget> actions = [];
if (cancelLabel != null && cancelListener != null) {
actions.add(
FlatButton(
key: UniqueKey(),
child: Text(
cancelLabel,
style: TextStyle(color: Colors.black),
),
onPressed: () {
Navigator.pop(context, cancelLabel);
cancelListener();
},
),
);
}
if (okLabel != null && okListener != null) {
actions.add(
FlatButton(
key: UniqueKey(),
child: Text(
okLabel,
style: TextStyle(color: Colors.black),
),
onPressed: () {
Navigator.pop(context, okLabel);
okListener();
},
),
);
}
showDialog<String>(
barrierDismissible: false,
context: context,
builder: (BuildContext context) => WillPopScope(
onWillPop: () {
return Future.value(false);
},
child: AlertDialog(
backgroundColor: Colors.white,
title: title,
content: content,
actions: actions,
),
),
).then((returnVal) {
if (returnVal != null && thenListener != null) {
thenListener();
}
});
}