shared_pref_navigation_saver 0.3.3 copy "shared_pref_navigation_saver: ^0.3.3" to clipboard
shared_pref_navigation_saver: ^0.3.3 copied to clipboard

This library will help to restore navigation stack after application kill.

Flutter navigation saver library (shared preferences module) #

This library will help to restore navigation stack after application kill.

Overview #

This library should be used if you have some special way of serializing arguments into the string and back. Also do not forget to check general readme.

How does this module work: #

  1. It uses the core module (git link or pub link) and extends it to save routes to the shared preferences.
  2. All the control of converting routes to string is up to the application user code.
  3. maximumDurationBetweenRestoration is used to understand if we need to restore routes or too much time was passed. Default is 5 minutes.

General implementation: #

  1. Include dependencies: shared_pref_navigation_saver: ^0.3.3 - current module
  2. Include any argument to disk saving library or write it by yourself. We suggest build value (git hub or pub link) or json module (git hub or pub link).
  3. Create NavigationSaver class before your application widget:
import 'package:build_value_navigation_saver/navigation_saver_routes_info.dart';
import 'package:shared_pref_navigation_saver/shared_pref_navigation_saver.dart';

void main() {
  final NavigationSaver _navigatorSaver = SharedPrefNavigationSaver(
    (Iterable<RouteSettings> routes) async => /* todo: add save code */,
    (String routesAsString) async => /* todo: add restore code */,
  );

  runApp(MyApp(_navigatorSaver));
}

  1. Setup NavigationSaver as navigation observer and route generator:
class MyApp extends StatelessWidget {
  MyApp(this._navigationSaver);

  final NavigationSaver _navigationSaver;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      initialRoute: NavigationSaver.restoreRouteName,
      onGenerateRoute: (RouteSettings routeSettings) => _navigationSaver.onGenerateRoute(
        routeSettings,
        (
          RouteSettings settings,
          String routeName,
          Object routeArguments, {
          NextPageInfo nextPageInfo,
        }) => /* todo: generate your application widgets here. use `routeName` and `routeArguments` */,
      ),
      navigatorObservers: [_navigationSaver],
    );
  }
}
  1. This is it. Also you may want to add custom restoration widget that will be shown when library restore your navigation stack. This can be done by passing restoreRouteWidgetBuilder parameter in onGenerateRoute method.
  2. You may want to add custom restoration widget that will be shown when library restore your navigation stack. This can be done by passing restoreRouteWidgetBuilder parameter in onGenerateRoute method.
  3. To see how to get result from restored routes see note in the core library: github or pub

Please check built value module (githib link or pub link) or json module (github link or pub link) for argument to map converting logic.

2
likes
40
points
24
downloads

Publisher

verified publisherscal.io

Weekly Downloads

This library will help to restore navigation stack after application kill.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation

License

BSD-3-Clause (license)

Dependencies

flutter, navigation_saver, shared_preferences

More

Packages that depend on shared_pref_navigation_saver