48 lines
1.6 KiB
Dart
48 lines
1.6 KiB
Dart
|
|
// What a page needs from the shell (lib/shell.dart), without importing it: open the
|
||
|
|
// menu, switch view. Pages import this; the shell imports the pages.
|
||
|
|
|
||
|
|
import 'package:flutter/material.dart';
|
||
|
|
|
||
|
|
/// Every view the menu offers. Tools are the rarely used ones (pirate-station-aide's pattern).
|
||
|
|
enum ShellView { dash, signals, captures, camera, linkTest, settings }
|
||
|
|
|
||
|
|
/// The landing view, set at build time: `--dart-define=YUKART_HOME=dash` for the car,
|
||
|
|
/// `signals` (the default, for now) while developing.
|
||
|
|
ShellView get landingView => switch (const String.fromEnvironment(
|
||
|
|
'YUKART_HOME',
|
||
|
|
defaultValue: 'signals',
|
||
|
|
)) {
|
||
|
|
'dash' => ShellView.dash,
|
||
|
|
_ => ShellView.signals,
|
||
|
|
};
|
||
|
|
|
||
|
|
/// The view on screen. The shell listens to it; anything may set it (the link-test hook does).
|
||
|
|
final shellView = ValueNotifier<ShellView>(landingView);
|
||
|
|
|
||
|
|
class ShellScope extends InheritedWidget {
|
||
|
|
const ShellScope({super.key, required this.openMenu, required super.child});
|
||
|
|
|
||
|
|
final VoidCallback openMenu;
|
||
|
|
|
||
|
|
static ShellScope? maybeOf(BuildContext context) =>
|
||
|
|
context.dependOnInheritedWidgetOfExactType<ShellScope>();
|
||
|
|
|
||
|
|
@override
|
||
|
|
bool updateShouldNotify(ShellScope old) => false;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// The menu button every page puts where a back arrow would be. The menu also opens
|
||
|
|
/// with a swipe in from the left edge.
|
||
|
|
class MenuButton extends StatelessWidget {
|
||
|
|
const MenuButton({super.key, this.color});
|
||
|
|
|
||
|
|
final Color? color;
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) => IconButton(
|
||
|
|
tooltip: 'Menu',
|
||
|
|
icon: Icon(Icons.menu, color: color),
|
||
|
|
onPressed: ShellScope.maybeOf(context)?.openMenu,
|
||
|
|
);
|
||
|
|
}
|