showStudioActionSheet<T> function

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

Asks which of a few actions to take: a sheet up from the bottom with title (and message), the actions as a column of full-width keys, and a cancel key apart under them. Gives the chosen action's value, or null.

showStudioActionSheet<String>(context: context, title: 'This take', actions: const [StudioSheetAction(label: 'Keep', value: 'keep'), StudioSheetAction(label: 'Discard', value: 'discard', isDestructiveAction: true)])

Implementation

Future<T?> showStudioActionSheet<T>({
  required BuildContext context,
  required String title,
  required List<StudioSheetAction<T>> actions,
  String? message,
  String cancelLabel = 'Cancel',
}) => showStudioBottomSheet<T>(
  context: context,
  title: title,
  builder: (context) {
    final theme = StudioTheme.of(context);
    final c = theme.colors;
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      mainAxisSize: MainAxisSize.min,
      children: [
        if (message != null) ...[
          Text(
            message,
            style: theme.textTheme.secondary.copyWith(color: c.legendMuted),
          ),
          const SizedBox(height: StudioSpacing.regular),
        ],
        for (final (i, a) in actions.indexed) ...[
          if (i > 0) const SizedBox(height: StudioSpacing.small),
          SizedBox(
            height: theme.controlHeight + 4,
            child: StudioButton(
              a.label,
              icon: a.icon,
              isDestructiveAction: a.isDestructiveAction,
              onPressed: () => Navigator.of(context).pop(a.value),
            ),
          ),
        ],
        const SizedBox(height: StudioSpacing.large),
        SizedBox(
          height: theme.controlHeight + 4,
          child: StudioButton.text(
            cancelLabel,
            onPressed: () => Navigator.of(context).pop(),
          ),
        ),
      ],
    );
  },
);