showActionsSheet<T> function

Future<T?> showActionsSheet<T>(
  1. List<ActionSheetItem<T>> actions, {
  2. bool disabledCancel = false,
  3. String? cancelText,
  4. 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,
        );
      });
}