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
| static Future showConfirm({ BuildContext context, String title, Widget content, String cancelText, String confirmText, Function onCancel, Function onConfirm, AlertDialog Function(BuildContext context) builder }) async { var flag = await showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: title != null && title.isNotEmpty ? Text(title) : null, content: content, actions: <Widget>[ TextButton( onPressed: () => Navigator.of(context).pop(false), child: Text(cancelText ?? 'Cancel'), ), TextButton( onPressed: () => Navigator.of(context).pop(true), child: Text(confirmText ?? 'Confirm'), ) ] ); } ); if (flag != null && flag) { onConfirm(); } else if (onCancel != null) { onCancel(); } }
|