flutter_navigator 0.1.0 copy "flutter_navigator: ^0.1.0" to clipboard
flutter_navigator: ^0.1.0 copied to clipboard

discontinued
outdated

A flutter navigator service that allows communication to the Navigator API without build context.

FlutterNavigator #

FlutterNavigator is a dart library for dealing with the Navigator API without a build context. This package wraps the NavigatorKey and provides a cleaner service for navigating without context in your flutter application.

Installation #

Use the pubspec.yaml file to install the dependency.

flutter_navigator: ^0.1.0

Usage #

Using the Navigator Key #

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Navigator Key',
      navigatorKey: FlutterNavigator().navigatorKey,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const PageOne(),
    );
  }
}

You need to provide the navigator key to your MaterialApp as that is how the service will communicate with the navigator state without the build context.

Using the FlutterNavigator #

final FlutterNavigator _flutterNavigator = FlutterNavigator();

_flutterNavigator.push(PageTwo.route());

The FlutterNavigator is a singleton service so it will always keep the same instance throughout the lifetime of the application.

Using the FlutterNavigator Observers #

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Observers',
      navigatorKey: FlutterNavigator().navigatorKey,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      navigatorObservers: [
        FlutterNavigator().routeObserver,
      ],
      home: const PageOne(),
    );
  }
}

As with the navigator key, you can use the route observer provided by the service and this can be accessed throughout the application.

Creating your own implementation #

class CustomFlutterNavigator implements IFlutterNavigator

To create your own implementation, all you need to do is implement the interface IFlutterNavigator and provide all the needed methods and properties.

Examples #

  • BLoC Navigation - an example of how to use the FlutterNavigator within a BLoC.

Contributing #

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License #

MIT

6
likes
0
pub points
59%
popularity

Publisher

unverified uploader

A flutter navigator service that allows communication to the Navigator API without build context.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on flutter_navigator