showActionSheet<T> static method

Future<T?> showActionSheet<T>({
  1. Widget? title,
  2. Widget? content,
  3. List<Widget>? actions,
  4. Widget? cancel,
  5. VoidCallback? onCancel,
  6. ValueChanged<int>? onConfirm,
})

显示底部操作表

Implementation

static Future<T?> showActionSheet<T>({
  Widget? title,
  Widget? content,
  List<Widget>? actions,
  Widget? cancel,
  VoidCallback? onCancel,
  ValueChanged<int>? onConfirm,
}) async {
  final context = ComContext.context;
  final actionsList = (actions ?? []).asMap().entries.map((entry) {
    return CupertinoActionSheetAction(
      onPressed: () {
        if (onConfirm != null) {
          onConfirm(entry.key);
        }
        Navigator.of(context).pop();
      },
      child: entry.value,
    );
  }).toList();

  return await showModalBottomSheet(
    context: context,
    backgroundColor: Colors.transparent,
    builder: (context) => CupertinoActionSheet(
      title: title,
      message: content,
      actions: actionsList,
      cancelButton: CupertinoActionSheetAction(
        onPressed: () {
          if (onCancel != null) {
            onCancel();
          }
          Navigator.of(context).pop();
        },
        child: cancel ?? Text(ComLocalizations.of(context).cancel),
      ),
    ),
  );
}