redux_persist_flutter 0.8.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 96

redux_persist_flutter pub package

Flutter Storage Engine for redux_persist.

Can either save to shared_preferences (default, recommended), or your application document directory.

Usage #

final persistor = Persistor<State>(
  // ...
  storage: FlutterStorage(),
);

It is recommended to load initial state before calling runApp to let Flutter show the slash screen until we are ready to render.

Locations #

By default, it saves to FlutterSaveLocation.documentFile (application document directory, recommended).

You can also save to your shared preferences by using FlutterSaveLocation.sharedPreferences:

// Use shared preferences
FlutterStorage(location: FlutterSaveLocation.sharedPreferences);
// Use document file
FlutterStorage(location: FlutterSaveLocation.documentFile);

Key #

You can pass a key argument to FlutterStorage to provide a key for the file name (document file) or the shared preference key.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.8.0 - 2018-11-27

  • Release v0.8.0. Last v0.x release line.

0.8.0-rc.0 - 2018-11-06

  • Breaking: Changed required parameter key to optional named parameter.
  • Breaking: Remove gate. Load initial state before calling runApp.

0.6.0 - 2018-08-10

  • Breaking: Dart 2.
  • Breaking: Revert back to DocumentFileEngine as default.
  • Refactor.

0.5.0 - 2018-03-18

  • Breaking: Fix typo sharedPreference to sharedPreferences (and SharedPreferenceEngine to SharedPreferencesEngine). You will need to rename if you are using it explicitly.

0.4.6 - 2018-03-14

  • Fix library export.

0.4.5 - 2018-03-13

  • Update load listener from loadStream.listen to Future.

0.4.4 - 2018-03-12

  • Update redux_persist dependency.

0.4.3 - 2018-03-12

  • Fix load bug (loaded JSON instead of string)

0.4.2 - 2018-03-10

  • Breaking: Change PersistorGate child to builder.

0.4.1 - 2018-03-10

  • Breaking: Change PersistorGate from Widget to WidgetBuilder.

0.4.0 - 2018-03-10

  • Initial decoupling.

example/redux_persist_flutter_example.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:redux/redux.dart';
import 'package:redux_persist/redux_persist.dart';
import 'package:redux_persist_flutter/redux_persist_flutter.dart';

void main() async {
  // Create Persistor
  final persistor = Persistor<AppState>(
    storage: FlutterStorage(),
    serializer: JsonSerializer<AppState>(AppState.fromJson),
  );

  // Load initial state
  final initialState = await persistor.load();

  final store = Store<AppState>(
    reducer,
    initialState: initialState ?? AppState(),
    middleware: [persistor.createMiddleware()],
  );

  runApp(App(
    store: store,
  ));
}

// Redux
class AppState {
  final int counter;

  AppState({this.counter = 0});

  AppState copyWith({int counter}) =>
      AppState(counter: counter ?? this.counter);

  static AppState fromJson(dynamic json) =>
      AppState(counter: json["counter"] as int);

  dynamic toJson() => {'counter': counter};
}

class IncrementCounterAction {}

AppState reducer(AppState state, Object action) {
  if (action is IncrementCounterAction) {
    // Increment
    return state.copyWith(counter: state.counter + 1);
  }

  return state;
}

// App
class App extends StatelessWidget {
  final Store<AppState> store;

  const App({Key key, this.store}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // PersistorGaOuu te waits for state to be loaded before rendering
    return StoreProvider(
      store: store,
      child: MaterialApp(title: 'Redux Persist Demo', home: HomePage()),
    );
  }
}

// Counter example
class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Redux Persist demo"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            StoreConnector<AppState, String>(
              converter: (store) => store.state.counter.toString(),
              builder: (context, count) => Text(
                    '$count',
                    style: Theme.of(context).textTheme.display1,
                  ),
            ),
          ],
        ),
      ),
      floatingActionButton: StoreConnector<AppState, VoidCallback>(
        // Return a function to dispatch an increment action
        converter: (store) => () => store.dispatch(IncrementCounterAction()),
        builder: (_, increment) => FloatingActionButton(
              onPressed: increment,
              tooltip: 'Increment',
              child: Icon(Icons.add),
            ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  redux_persist_flutter: ^0.8.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:redux_persist_flutter/redux_persist_flutter.dart';
  
Version Uploaded Documentation Archive
0.8.1 Feb 11, 2019 Go to the documentation of redux_persist_flutter 0.8.1 Download redux_persist_flutter 0.8.1 archive
0.8.0 Nov 27, 2018 Go to the documentation of redux_persist_flutter 0.8.0 Download redux_persist_flutter 0.8.0 archive
0.6.0 Aug 10, 2018 Go to the documentation of redux_persist_flutter 0.6.0 Download redux_persist_flutter 0.6.0 archive
0.5.0 Mar 19, 2018 Go to the documentation of redux_persist_flutter 0.5.0 Download redux_persist_flutter 0.5.0 archive
0.4.6 Mar 14, 2018 Go to the documentation of redux_persist_flutter 0.4.6 Download redux_persist_flutter 0.4.6 archive
0.4.5 Mar 13, 2018 Go to the documentation of redux_persist_flutter 0.4.5 Download redux_persist_flutter 0.4.5 archive
0.4.4 Mar 12, 2018 Go to the documentation of redux_persist_flutter 0.4.4 Download redux_persist_flutter 0.4.4 archive
0.4.3 Mar 12, 2018 Go to the documentation of redux_persist_flutter 0.4.3 Download redux_persist_flutter 0.4.3 archive
0.4.2 Mar 10, 2018 Go to the documentation of redux_persist_flutter 0.4.2 Download redux_persist_flutter 0.4.2 archive
0.4.1 Mar 10, 2018 Go to the documentation of redux_persist_flutter 0.4.1 Download redux_persist_flutter 0.4.1 archive

All 13 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
93
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
96
Learn more about scoring.

We analyzed this package on Jun 12, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.1
  • pana: 0.12.17
  • Flutter: 1.5.4-hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
flutter 0.0.0
path_provider ^0.5.0+1 0.5.0+1 1.1.0
redux_persist ^0.8.0 0.8.2
shared_preferences ^0.5.1+1 0.5.3+1
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
redux 3.0.0
sky_engine 0.0.99
synchronized 2.1.0
typed_data 1.1.6
vector_math 2.0.8