aabd22b5ad
Replace the narrow-layout floating destination pill with a full-width Material 3 NavigationBar. Reuse the shell destination model and badge wiring while preserving re-selection callbacks and hiding the bar for keyboard/detail states.
65 lines
2.3 KiB
Dart
65 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'destination.dart';
|
|
|
|
/// The destinations the phone's bottom bar offers, in order: the tabs, then
|
|
/// Settings. The rail pins Settings at its foot; a narrow window has no foot,
|
|
/// so Settings is the bar's last destination and is selected while it is open.
|
|
const List<AppDestination> shellBarDestinations = [
|
|
...shellTabDestinations,
|
|
AppDestination.settings,
|
|
];
|
|
|
|
/// The phone layout's bottom navigation: a full-width Material
|
|
/// [NavigationBar] with an icon and a label per destination, the current
|
|
/// destination marked by the bar's indicator.
|
|
///
|
|
/// [icon] builds each destination's icon (its running, needs-you or unread
|
|
/// badge included), the same builder the desktop rail uses, so both layouts
|
|
/// show the same counts. [selected] is the shell's destination. A re-tap of
|
|
/// the selected destination still calls [onSelected], which is how the shell's
|
|
/// destination-reselected hook fires.
|
|
///
|
|
/// The bar keeps the bottom system inset (gesture bar) clear and leaves while
|
|
/// the keyboard is open, so a field's text is never covered by the bar.
|
|
class ShellNavigationBar extends StatelessWidget {
|
|
const ShellNavigationBar({
|
|
super.key,
|
|
required this.selected,
|
|
required this.icon,
|
|
required this.onSelected,
|
|
});
|
|
|
|
final AppDestination selected;
|
|
final Widget Function(AppDestination destination) icon;
|
|
final ValueChanged<AppDestination> onSelected;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// The keyboard takes the bottom of the window: the bar leaves with it.
|
|
if (MediaQuery.viewInsetsOf(context).bottom > 0) {
|
|
return const SizedBox.shrink();
|
|
}
|
|
return SafeArea(
|
|
top: false,
|
|
child: NavigationBar(
|
|
key: const ValueKey('shell.navigation-bar'),
|
|
selectedIndex: shellBarDestinations.indexOf(selected),
|
|
onDestinationSelected: (value) =>
|
|
onSelected(shellBarDestinations[value]),
|
|
destinations: [
|
|
for (final destination in shellBarDestinations)
|
|
NavigationDestination(
|
|
icon: KeyedSubtree(
|
|
key: ValueKey('shell.destination.${destination.name}'),
|
|
child: icon(destination),
|
|
),
|
|
label: destinationDetails(destination).label,
|
|
tooltip: destinationDetails(destination).label,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|