showPopupMenuFallbackSheet function
Future<List<int> ?>
showPopupMenuFallbackSheet(
- BuildContext context,
- List<
CNPopupMenuEntry> entries, { - String? title,
Shows entries in a CupertinoActionSheet and returns the path to the
selected item, opening a further sheet for each nested submenu on the
way. Returns null when the user cancels.
An inline or palette submenu is listed in place, its label above its items, which report the same paths as if it were nested.
Implementation
Future<List<int>?> showPopupMenuFallbackSheet(
BuildContext context,
List<CNPopupMenuEntry> entries, {
String? title,
}) async {
final rows = _rows(entries, const []).toList();
final selected = await showCupertinoModalPopup<List<int>>(
context: context,
builder: (ctx) {
return CupertinoActionSheet(
title: title != null ? Text(title) : null,
actions: [
for (final (path, entry, header) in rows)
if (header)
Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),
child: Text(
(entry as CNPopupMenuSubmenu).label,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 13,
color: CupertinoColors.secondaryLabel.resolveFrom(ctx),
),
),
)
else if (entry case final CNPopupMenuItem item)
_fallbackAction(
enabled: item.enabled,
onPressed: () => Navigator.of(ctx).pop(path),
isDestructiveAction: item.isDestructive,
child: _fallbackLabel(ctx, item.label, item.subtitle),
)
else if (entry case final CNPopupMenuSubmenu submenu)
_fallbackAction(
enabled: submenu.enabled,
onPressed: () => Navigator.of(ctx).pop(path),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: _fallbackLabel(
ctx,
submenu.label,
submenu.subtitle,
),
),
const SizedBox(width: 6),
const Icon(CupertinoIcons.chevron_forward, size: 16),
],
),
)
else
const SizedBox(height: 8),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.of(ctx).pop(),
isDefaultAction: true,
child: const Text('Cancel'),
),
);
},
);
if (selected == null) return null;
final entry = rows.firstWhere((r) => !r.$3 && _same(r.$1, selected)).$2;
if (entry is! CNPopupMenuSubmenu) return selected;
if (!context.mounted) return null;
final rest = await showPopupMenuFallbackSheet(
context,
entry.items,
title: entry.label,
);
return rest == null ? null : [...selected, ...rest];
}