yShowActionSheet function

void yShowActionSheet(
  1. String message,
  2. List<String> actions,
  3. dynamic onCallBack(
    1. int index,
    2. String action
    ), {
  4. dynamic onCancel()?,
  5. BuildContext? context,
})

弹出actionsheet

Implementation

void yShowActionSheet(String message, List<String> actions, Function(int index, String action) onCallBack, {Function()? onCancel, BuildContext? context}) async {
  final result = await showModalActionSheet<String>(
    context: context ?? yPages.last.context,
    actions: actions.map<SheetAction<String>>((e) => SheetAction(key: e, label: e)).toList(),
    isDismissible: true,
    useRootNavigator: true,
    cancelLabel: "取消",
    message: message,
    title: "请选择",
  );
  var i = 0;
  int? index;
  for (var element in actions) {
    if (element == result) index = i;
    i++;
  }
  if (index != null && result != null) {
    onCallBack(index, result);
  } else {
    onCancel?.call();
  }
}