routed_widget_switcher 1.0.4 copy "routed_widget_switcher: ^1.0.4" to clipboard
routed_widget_switcher: ^1.0.4 copied to clipboard

Declaratively switch child widgets based on the current `Router` location.

example/lib/main.dart

import 'package:example/router_examples/beamer_app.dart';
import 'package:example/router_examples/routermaster_app.dart';
import 'package:flutter/material.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) {
    Widget buildSideBarBg(Widget child) => Material(child: SizedBox(width: 180, child: child));
    return buildSideBarBg(
      RoutedWidgetSwitcher(
        builders: [
          PathBuilder('*', builder: (_) => const MainMenu()),
          PathBuilder('/dashboard', builder: (_) => const DashboardMenu()),
          PathBuilder('/settings', builder: (_) => const SettingsMenu()),
        ],
      ),
    );
  }
}
18
likes
150
points
60
downloads

Publisher

verified publishergskinner.com

Weekly Downloads

Declaratively switch child widgets based on the current `Router` location.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, path_to_regexp

More

Packages that depend on routed_widget_switcher