navme 0.9.0 copy "navme: ^0.9.0" to clipboard
navme: ^0.9.0 copied to clipboard

outdated

A simple way to use Navigation 2.0

navme by zfx.com #

Pub

Import #

navme: 0.9.0
import 'package:navme/navme.dart';

Example use #

 // config page
 class BooksListNavigate {
  // base path
  static String path = 'book';

  // config for configurate Router
  static RouteConfig routeConfig = RouteConfig(
    state: RouteState(uri: path.toUri()),
    // condition for using this page
    isThisPage: (RouteState state) {
      if ((state?.firstPath == path || state?.uri?.pathSegments?.isEmpty == true) && !state.hasParams) {
        return true;
      }
      return false;
    },
    // settigs from url
    settings: (RouteState state) {
      return null;
    },
    // get Page for Router
    page: ({RouteState state}) {
      return MaterialPage(key: const ValueKey('BooksListPage'), child: BooksListScreen.all(), name: 'BooksListScreen');
    },
  );
}
class NavmeRouterDelegate extends BaseRouterDelegate {
  NavmeRouterDelegate()
      : super(
          // base route
          initConfig: BooksListNavigate.routeConfig,
          configs: [
            // pages
            BookDetailsNavigate.routeConfig,
            BooksListNavigate.routeConfig,
            FadeNavigate.routeConfig,
            NestedNavigate.routeConfig,
            UnknownNavigate.routeConfig,
          ],
        );

  @override
  RouteState get currentConfiguration {
    return currentState;
  }

  // helper
  static NavmeRouterDelegate of(BuildContext context) {
    final delegate = Router.of(context).routerDelegate;
    if (delegate is NavmeRouterDelegate) {
      return delegate;
    }
    assert(() {
      throw FlutterError('Router operation requested with a context that does not include a NavmeRouterDelegate.\n');
    }(), 'Router operation requested with a context that does not include a NavmeRouterDelegate.\n');
    return null;
  }

  @override
  Widget build(BuildContext context) {
    return Navigator(
      key: navigatorKey,
      observers: [HeroController()], // THIS IS THE IMPORTANT LINE for Hero
      pages: buildPage(), // your stack pages
      onPopPage: (route, result) {
        if (!route.didPop(result)) {
          return false;
        }
        pop();
        return true;
      },
    );
  }
}

Todo: #

  • return url
  • nested url
  • open dialog
13
likes
0
pub points
27%
popularity

Publisher

verified publisherzfx.com

A simple way to use Navigation 2.0

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on navme