json_navigation_saver 0.2.0+1 copy "json_navigation_saver: ^0.2.0+1" to clipboard
json_navigation_saver: ^0.2.0+1 copied to clipboard

outdated

This library is a helper library for converting routes with arguments to a string.

example/lib/main.dart

import 'dart:convert';

import 'package:example/home/home_page.dart';
import 'package:example/home/home_page_arguments.dart';
import 'package:flutter/material.dart';
import 'package:json_navigation_saver/json_navigation_saver.dart';
import 'package:navigation_saver/navigation_saver.dart';
import 'package:shared_pref_navigation_saver/shared_pref_navigation_saver.dart';

void main() {
  final NavigationSaver _navigatorSaver = SharedPrefNavigationSaver(
    (Iterable<RouteSettings> routes) async =>
        json.encode(serializeRoutes(routes)),
    (String routesAsString) async =>
        deserializeRoutes(json.decode(routesAsString)),
  );

  runApp(MyApp(_navigatorSaver));
}

class MyApp extends StatelessWidget {
  MyApp(this._navigationSaver);

  final NavigationSaver _navigationSaver;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      initialRoute: NavigationSaver.restoreRouteName,
      onGenerateRoute: (RouteSettings routeSettings) =>
          _navigationSaver.onGenerateRoute(
        routeSettings,
        (
          RouteSettings settings, {
          NextPageInfo nextPageInfo,
        }) =>
            MaterialPageRoute(
          builder: (BuildContext context) => MyHomePage(
            initialCounter: settings.arguments is Map
                ? MyHomePageArguments.fromJson(
                        settings.arguments as Map<String, dynamic>)
                    .deepIndex
                : 0,
            nextPageInfo: nextPageInfo,
          ),
          settings: routeSettings,
        ),
      ),
      navigatorObservers: [_navigationSaver],
    );
  }
}
0
likes
0
pub points
0%
popularity

Publisher

verified publisherscal.io

This library is a helper library for converting routes with arguments to a string.

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

flutter, json_annotation, navigation_saver

More

Packages that depend on json_navigation_saver