showActionsSheet<T> function
Future<T?>
showActionsSheet<T>(
- List<
ActionSheetItem< actions, {T> > - bool disabledCancel = false,
- String? cancelText,
- TextStyle? cancelStyle,
Actions sheet pops up from the bottom of the screen
enum MyActions { UPDATE, DELETE }
Future<void> openActionDialog() async {
switch (await showActionsSheet<MyActions>([
ActionSheetItem(value: MyActions.UPDATE, text: 'Update'),
ActionSheetItem(value: MyActions.DELETE, text: 'Delete'),
])) {
case MyActions.UPDATE:
// implement ...
break;
case MyActions.DELETE:
// implement ...
break;
}
}
Implementation
Future<T?> showActionsSheet<T>(List<ActionSheetItem<T>> actions,
{bool disabledCancel = false,
String? cancelText,
TextStyle? cancelStyle}) async {
List<Widget> actionsWidget = [];
actions.forEach((item) {
actionsWidget.add(
CupertinoActionSheetAction(
onPressed: () async {
Navigator.pop(await getxContext, item.value);
},
child: Text(item.text, style: item.style),
),
);
});
return await showCupertinoModalPopup(
context: await getxContext,
builder: (context) {
return CupertinoActionSheet(
actions: actionsWidget,
cancelButton: false == disabledCancel
? CupertinoActionSheetAction(
onPressed: () {
Navigator.pop(context, null);
},
child: Text(
cancelText ?? WaffLocalizations.S('cancel'),
style: cancelStyle,
),
)
: null,
);
});
}