show static method

Future<int?> show({
  1. required BuildContext context,
  2. String? title,
  3. String? message,
  4. required List<BaseActionSheetAction> actions,
  5. BaseActionSheetAction? cancelAction,
  6. BaseParam? cupertino,
  7. BaseParam? material,
})

Shows a native action sheet

  • context: Build context for showing the sheet
  • title: Title text (keep short, ideally single line)
  • message: Optional message for additional context
  • actions: List of actions to display (destructive actions should be first)
  • cancelAction: Optional cancel action (recommended, especially for destructive actions)
  • cupertino: Cupertino-specific parameters
  • material: Material-specific parameters

Returns the index of the action that was tapped, or null if cancelled

Implementation

static Future<int?> show({
  required BuildContext context,
  String? title,
  String? message,
  required List<BaseActionSheetAction> actions,
  BaseActionSheetAction? cancelAction,
  BaseParam? cupertino,
  BaseParam? material,
}) async {
  if (actions.isEmpty) {
    throw ArgumentError('Actions list cannot be empty');
  }

  // Determine which platform implementation to use
  final useCupertino = _shouldUseCupertino(context, cupertino, material);

  if (useCupertino) {
    // Convert BaseActionSheetAction to CNActionSheetAction for iOS
    final cnActions = actions.map((action) => action.toCNActionSheetAction()).toList();
    final cnCancelAction = cancelAction?.toCNActionSheetAction();

    return await _showCupertinoNativeActionSheet(
      title: title,
      message: message,
      actions: cnActions,
      cancelAction: cnCancelAction,
    );
  } else {
    return await _showMaterialBottomSheet(
      context: context,
      title: title,
      message: message,
      actions: actions,
      cancelAction: cancelAction,
    );
  }
}