shared_pref_navigation_saver 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 73

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.2.0 - 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.

[0.2.1] - 25.11.2019

  • Read.me update

[0.2.0+1] - 25.11.2019

  • Read.me update

[0.2.0] - 25.11.2019

  • Read.me update

[0.1.0+2] - 25.11.2019

  • Read.me update

[0.1.0+1] - 25.11.2019

  • Read.me update

[0.1.0] - 25.11.2019

  • Add example project

[0.0.1] - 22.11.2019

  • Initial release.

example/README.md

Flutter navigation saver library example (built value module) #

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

Overview #

This example shows how to use our library with a combination of built value.

How to use our library is located here

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  shared_pref_navigation_saver: ^0.2.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:shared_pref_navigation_saver/shared_pref_navigation_saver.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
46
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health issues and suggestions

Document public APIs. (-1 points)

5 out of 5 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
navigation_saver ^0.2.0 0.2.1
shared_preferences ^0.5.0 0.5.6
Transitive dependencies
collection 1.14.11 1.14.12
flutter_web_plugins 0.0.0
meta 1.1.8
shared_preferences_macos 0.0.1+3
shared_preferences_platform_interface 1.0.1
shared_preferences_web 0.1.2+2
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
pedantic ^1.7.0 1.9.0