yShowSelectBuilder function

void yShowSelectBuilder(
  1. String message,
  2. bool cancelAble,
  3. List<String> actions,
  4. dynamic onCallBack(
    1. int index,
    2. String action
    ), {
  5. dynamic onCancelBack()?,
  6. BuildContext? context,
})

弹出单选框

Implementation

void yShowSelectBuilder(String message, bool cancelAble, List<String> actions, Function(int index, String action) onCallBack, {Function()? onCancelBack, BuildContext? context}) async {
  final result = await showConfirmationDialog(
    context: context ?? yPages.last.context,
    message: message,
    title: "请选择",
    cancelLabel: cancelAble ? "取消" : null,
    actions: actions.map<AlertDialogAction<String>>((e) => AlertDialogAction(key: e, label: e)).toList(),
    useRootNavigator: true,
    barrierDismissible: false,
    okLabel: "确定",
  );
  var i = 0;
  int? index;
  for (var element in actions) {
    if (element == result) index = i;
    i++;
  }
  if (index == null) {
    onCancelBack?.call();
    return;
  }
  onCallBack(index!, result!);
}