Keep chat controls readable and expose labeled app navigation
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'destination.dart';
|
||||
|
||||
/// Native, labeled destination access when the full tab bar cannot fit a rail.
|
||||
class ShellDestinationMenu extends StatelessWidget {
|
||||
const ShellDestinationMenu({
|
||||
super.key,
|
||||
required this.cupertino,
|
||||
required this.current,
|
||||
required this.onSelected,
|
||||
});
|
||||
final bool cupertino;
|
||||
final AppDestination current;
|
||||
final ValueChanged<AppDestination> onSelected;
|
||||
|
||||
Future<void> _choose(BuildContext context) async {
|
||||
final value = await showCupertinoModalPopup<AppDestination>(
|
||||
context: context,
|
||||
builder: (context) => CupertinoActionSheet(
|
||||
title: const Text('Main navigation'),
|
||||
actions: [
|
||||
for (final destination in AppDestination.values)
|
||||
CupertinoActionSheetAction(
|
||||
isDefaultAction: destination == current,
|
||||
onPressed: () => Navigator.pop(context, destination),
|
||||
child: Text(destinationDetails(destination).label),
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (value != null && context.mounted) onSelected(value);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final child = Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(cupertino ? CupertinoIcons.square_grid_2x2 : Icons.apps),
|
||||
const Text('Menu'),
|
||||
],
|
||||
);
|
||||
if (cupertino) {
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: 'Main navigation',
|
||||
child: CupertinoButton(onPressed: () => _choose(context), child: child),
|
||||
);
|
||||
}
|
||||
return PopupMenuButton<AppDestination>(
|
||||
tooltip: 'Main navigation',
|
||||
onSelected: onSelected,
|
||||
itemBuilder: (context) => [
|
||||
for (final destination in AppDestination.values)
|
||||
CheckedPopupMenuItem(
|
||||
value: destination,
|
||||
checked: destination == current,
|
||||
child: Text(destinationDetails(destination).label),
|
||||
),
|
||||
],
|
||||
child: Padding(padding: const EdgeInsets.all(8), child: child),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user