actions<T> static method

Future<T?> actions<T>(
  1. BuildContext context, {
  2. required List<XBottomSheetAction<T>> actions,
  3. String? title,
  4. String? message,
  5. String cancelLabel = 'Cancel',
  6. bool showCancel = true,
})

Shows a typed list of actions and returns the selected value.

Implementation

static Future<T?> actions<T>(
  BuildContext context, {
  required List<XBottomSheetAction<T>> actions,
  String? title,
  String? message,
  String cancelLabel = 'Cancel',
  bool showCancel = true,
}) {
  return show<T>(
    context,
    builder: (sheetContext) => Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: [
        if (title != null)
          Padding(
            padding: const EdgeInsets.fromLTRB(24, 8, 24, 4),
            child: Text(
              title,
              style: Theme.of(sheetContext).textTheme.titleLarge,
            ),
          ),
        if (message != null)
          Padding(
            padding: const EdgeInsets.fromLTRB(24, 0, 24, 12),
            child: Text(message),
          ),
        Flexible(
          child: ListView(
            shrinkWrap: true,
            children: [
              for (final action in actions)
                ListTile(
                  enabled: action.enabled,
                  leading: action.icon,
                  title: Text(
                    action.label,
                    style: action.isDestructive
                        ? TextStyle(
                            color: Theme.of(sheetContext).colorScheme.error,
                          )
                        : null,
                  ),
                  subtitle: action.subtitle == null
                      ? null
                      : Text(action.subtitle!),
                  onTap: action.enabled
                      ? () => Navigator.of(sheetContext).pop(action.value)
                      : null,
                ),
            ],
          ),
        ),
        if (showCancel)
          SafeArea(
            top: false,
            child: Padding(
              padding: const EdgeInsets.all(12),
              child: OutlinedButton(
                onPressed: () => Navigator.of(sheetContext).pop(),
                child: Text(cancelLabel),
              ),
            ),
          ),
      ],
    ),
  );
}