routed_widget_switcher 1.0.3+2 routed_widget_switcher: ^1.0.3+2 copied to clipboard
Declaratively switch child widgets based on the current `Router` location.
import 'package:example/router_examples/beamer_app.dart';
import 'package:example/router_examples/routermaster_app.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:routed_widget_switcher/routed_widget_switcher.dart';
import 'router_examples/go_router_app.dart';
import 'router_examples/vrouter_app.dart';
import 'widgets.dart';
void main() {
runApp(MultiAppTestRig(
tests: [
(_) => GoRouterApp(),
(_) => VRouterApp(),
(_) => RouteMasterApp(),
(_) => BeamerApp(),
],
));
}
/// Embedded within any of the example app scaffolds, this widget uses
/// `RoutedWidgetSwitcher` to switch children when router location changes.
class SideBar extends StatelessWidget {
const SideBar({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Material(
child: Container(
width: 180,
color: Colors.grey,
child: RoutedWidgetSwitcher(
builders: [
PathBuilder('*', builder: (_) => const MainMenu()),
PathBuilder('/dashboard', builder: (_) => const DashboardMenu()),
PathBuilder('/settings', builder: (_) => const SettingsMenu()),
],
),
),
);
}
}
/// The demo is driven by keyboard listeners that allow you to quickly switch locations.
Map<LogicalKeyboardKey, String> get keyboardMappings => {
LogicalKeyboardKey.digit1: '/',
LogicalKeyboardKey.digit2: '/pageA',
LogicalKeyboardKey.digit3: '/pageB',
LogicalKeyboardKey.digit4: '/dashboard',
LogicalKeyboardKey.digit5: '/dashboard/foo',
LogicalKeyboardKey.digit6: '/dashboard/bar',
LogicalKeyboardKey.digit7: '/settings',
LogicalKeyboardKey.digit8: '/settings/foo',
LogicalKeyboardKey.digit9: '/settings/bar',
};