flutter_built_redux 0.4.3

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 90

Pub codecov.io

flutter_built_redux

built_redux bindings for Flutter.

By creating a Widget that extends StoreConnector you get automatic subscribing to your redux store, and you component will only call setState when the store triggers and the values you take from the store in connect change!

Examples

todo_mvc, written by Brian Egan

Why you may need flutter_built_redux

For the same reason you would want to use redux with react.

from the flutter tutorial:

In Flutter, change notifications flow “up” the widget hierarchy by way of callbacks, while current state flows “down” to the stateless widgets that do presentation.

Following this pattern requires you to send any state or state mutator callbacks that are common between your widgets down from some common ancestor.

With larger applications this is very tedious, leads to large widget constructors, and this pattern causes flutter to rerun the build function on all widgets between the ancestor that contains the state and the widget that actually cares about it. It also means your business logic and network requests live in your widget declarations.

built_redux gives you a predicable state container that can live outside your widgets and perform logic in action middleware.

flutter_built_redux lets a widget to subscribe to the pieces of the redux state tree that it cares about. It also lets lets widgets dispatch actions to mutate the redux state tree. This means widgets can access and mutate application state without the state and state mutator callbacks being passed down from its ancestors!

Consuming - Simple Counter Example

Wrap your top-level flutter widget with ReduxProvider. This provides all child widgets with access to the store.

class ProviderWidget extends StatelessWidget {
  final Store<Counter, CounterBuilder, CounterActions> store;

  ProviderWidget(this.store);

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'flutter_built_redux - Counter Example',
      home: new ReduxProvider(
        store: store,
        child: new CounterWidget(),
      ),
    );
  }
}

Write a widget that extends StoreConnector. Declare the properties from your state you want this widget to subscribe to by implementing the connect & build methods. In this case we are subscribing to the count property from the Counter built_value


// first 3 generics are the redux store value, builder and actions, while the last
// one is the local state's value.
class CounterWidget extends StoreConnector<Counter, CounterActions, int> {
  CounterWidget({Key key}) : super(key: key);

  @override
  int connect(Counter state) => state.count;

  @override
  Widget build(BuildContext context, int count, CounterActions actions) {
    return new Scaffold(
      body: new Row(
        children: <Widget>[
          new RaisedButton(
            onPressed: actions.increment, // dispatches a built_redux action
            child: new Text('Increment'),
          ),
          new Text('Count: $count'), // renders the count value from the built_redux store
        ],
      ),
    );
  }
}

For context, the redux store in this example may look like:

Store<Counter, CounterBuilder, CounterActions> createStore() => new Store(
      createReducer(),
      new Counter(),
      new CounterActions(),
    );

Reducer<Counter, CounterBuilder, dynamic> createReducer() =>
    (new ReducerBuilder<Counter, CounterBuilder>()
          ..add(CounterActionsNames.increment, (s, a, b) => b.count++).build();

abstract class CounterActions extends ReduxActions {
  factory CounterActions() => new _$CounterActions();
  CounterActions._();

  ActionDispatcher<Null> get increment;
}

abstract class Counter implements Built<Counter, CounterBuilder> {
  factory Counter() => new _$Counter._(count: 0);
  Counter._();

  int get count;
}

0.4.3

  • Move built_value dependency to dev_dependencies and bump to ^5.0.0

0.4.2

  • Use assert for type assertions rather than thowing exceptions

0.4.1

  • Add changelog

0.4.0

  • Breaking changes:

    • Remove state builder generic from StoreConnector

    • Made StoreConnectorState private

  • Perform check on storeSub in didChangeDependencies to return early if a subscription to the store has already been created.

  • Raise exceptions if the store found by inheritFromWidgetOfExactType has different generics than the StoreConnector

  • Add unit tests

1. Depend on it

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


dependencies:
  flutter_built_redux: "^0.4.3"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_built_redux/flutter_built_redux.dart';
        
Version Uploaded Documentation Archive
0.4.3 Feb 1, 2018 Go to the documentation of flutter_built_redux 0.4.3 Download flutter_built_redux 0.4.3 archive
0.4.2 Jan 19, 2018 Go to the documentation of flutter_built_redux 0.4.2 Download flutter_built_redux 0.4.2 archive
0.4.1 Jan 7, 2018 Go to the documentation of flutter_built_redux 0.4.1 Download flutter_built_redux 0.4.1 archive
0.4.0 Jan 7, 2018 Go to the documentation of flutter_built_redux 0.4.0 Download flutter_built_redux 0.4.0 archive
0.3.0 Oct 22, 2017 Go to the documentation of flutter_built_redux 0.3.0 Download flutter_built_redux 0.3.0 archive
0.2.0 Oct 13, 2017 Go to the documentation of flutter_built_redux 0.2.0 Download flutter_built_redux 0.2.0 archive
0.1.0 Sep 28, 2017 Go to the documentation of flutter_built_redux 0.1.0 Download flutter_built_redux 0.1.0 archive
0.0.2 Aug 13, 2017 Go to the documentation of flutter_built_redux 0.0.2 Download flutter_built_redux 0.0.2 archive
0.0.1 May 15, 2017 Go to the documentation of flutter_built_redux 0.0.1 Download flutter_built_redux 0.0.1 archive

Analysis

This feature is new.
We welcome feedback.
More details: scoring.

We analyzed this package, and provided a score, details, and suggestions below.

  • tool failures on Feb 14, 2018
  • Dart: 2.0.0-dev.20.0
  • pana: 0.10.1
  • Flutter: 0.0.22

Scores

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

Platforms

Detected platforms: unsure

Error(s) prevent platform classification.

Suggestions

  • Fix dependencies in pubspec.yaml.

    Running flutter packages pub upgrade failed with the following output:

    ERR: Invalid argument(s): Minimum version ("2.0.0-dev.23.0") must be less than maximum ("2.0.0-dev.16.0").
    ERR: package:pub_semver/src/version_range.dart 59         new VersionRange
     package:pub/src/pubspec.dart 366                     Pubspec._ensureEnvironment
     package:pub/src/pubspec.dart 331                     Pubspec.dartSdkConstraint
     package:pub/src/solver/backtracking_solver.dart 511  BacktrackingSolver._checkPubspecMatchesSdkConstraint
     package:pub/src/solver/backtracking_solver.dart 474  BacktrackingSolver._checkVersion
     ===== asynchronous gap ===========================
     package:pub/src/solver/backtracking_solver.dart 432  BacktrackingSolver._findValidVersion.<fn>
     ===== asynchronous gap ===========================
     dart:async                                           Future.doWhile
     package:pub/src/solver/backtracking_solver.dart 430  BacktrackingSolver._findValidVersion
     package:pub/src/solver/backtracking_solver.dart 337  BacktrackingSolver._versionQueueFor
     ===== asynchronous gap ===========================
     package:pub/src/solver/backtracking_solver.dart 290  BacktrackingSolver._solve.<fn>
     ===== asynchronous gap ===========================
     dart:async                                           _completeOnAsyncReturn
     package:pub/src/solver/backtracking_solver.dart 315  BacktrackingSolver._solve.<fn>
     dart:async                                           _completeOnAsyncReturn
     package:pub/src/solver/version_selection.dart 64     VersionSelection.select
     dart:async                                           _completeOnAsyncReturn
     package:pub/src/solver/version_selection.dart 91     VersionSelection._addDependencies
     dart:async                                           _completeOnAsyncReturn
     package:pub/src/solver/version_selection.dart 91     VersionSelection._addDependencies
    ERR: This is an unexpected error. Please run
     
         pub --trace upgrade --verbosity io --no-precompile
     
     and include the logs in an issue on https://github.com/dart-lang/pub/issues/new
    
  • Fix platform conflicts.

    Make sure none of the libraries use mutually exclusive dependendencies.

  • Fix issues reported by dartanalyzer.

    dartanalyzer reported 1 error(s) and 0 warning(s).

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use flutter_built_redux.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0 <2.0.0