showActionSheet function

Future<int?> showActionSheet({
  1. required BuildContext context,
  2. required List<ActionSheetItem> items,
  3. String? title,
  4. String? subtitle,
  5. String? cancelLabel = 'Cancel',
})

Shows an action sheet with a list of actions.

Implementation

Future<int?> showActionSheet({
  required BuildContext context,
  required List<ActionSheetItem> items,
  String? title,
  String? subtitle,
  String? cancelLabel = 'Cancel',
}) =>
    showBottomSheet<int>(
      context: context,
      child: BottomSheet(
        title: title,
        subtitle: subtitle,
        content: Column(
          children: <Widget>[
            for (int i = 0; i < items.length; i++)
              Padding(
                padding: const EdgeInsets.only(bottom: 8),
                child: _ActionSheetTile(
                  item: items[i],
                  onTap: items[i].enabled
                      ? () => Navigator.of(context).pop(i)
                      : null,
                ),
              ),
          ],
        ),
        actions: cancelLabel == null
            ? null
            : <Widget>[
                SizedBox(
                  width: double.infinity,
                  child: OutlinedButton(
                    onPressed: () => Navigator.of(context).pop(),
                    child: Text(cancelLabel),
                  ),
                ),
              ],
      ),
    );