flutter_redurx 0.4.3

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

Flutter-ReduRx Build Status

Flutter bindings for ReduRx.

It provides a Provider as an InheritedWidget so you can reach the ReduRx Store wherever you have a BuildContext.<br> It also has a Connect Widget so you can grab a few parts of the State (sub-state/props) and it will automatically recall builder whenever only this little connected part of the State has changed preventing unnecessary rebuilds.

Getting started

API

Connect

  • convert: State -> Props - A function used by map to transform the state in a sub-state/props.
  • where: Props oldProps, Props newProps -> bool - A function to explicitly filter when the builder should be called.
  • builder: Props newProps -> Widget - A function that receives the sub-state/props and returns a Widget.
Connect<State, String>(
  convert: (state) => state.title,
  where: (oldTitle, newTitle) => newTitle != oldTitle,
  builder: (title) => Text(title),
)

Provider

  • store - A ReduRx Store.
  • child - Your application's Widget.
  • static dispatch<S>(BuildContext, ActionType) - Helper to call dispatch on the Provider's context Store.
Provider(
  store: Store<State>(State('Initial title')),
  child: App(),
)
Provider.dispatch<State>(context, ChangeTitle('New title'));

For a better understanding of dispatch and ActionType head to ReduRx.

Example

import 'package:flutter/material.dart' hide State;
import 'package:flutter_redurx/flutter_redurx.dart';

class State {
  State({this.title, this.count});
  final String title;
  final int count;
}

class Increment extends Action<State> {
  @override
  State reduce(State state) =>
      State(title: state.title, count: state.count + 1);
}

void main() {
  final store =
      Store<State>(State(title: 'Flutter-ReduRx Demo Title', count: 0));
  runApp(Provider(store: store, child: MyApp()));
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter-ReduRx Demo',
      theme: ThemeData(
        primarySwatch: Colors.pink,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Connect<State, String>(
            convert: (state) => state.title,
            where: (prev, next) => next != prev,
            builder: (title) => Text(title ?? ''),
          ),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('You have pushed the button this many times:'),
              Connect<State, String>(
                convert: (state) => state.count.toString(),
                where: (prev, next) => next != prev,
                builder: (count) => Text(count ?? '',
                    style: Theme.of(context).textTheme.display1),
              ),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () => Provider.dispatch<State>(context, Increment()),
          tooltip: 'Increment',
          child: Icon(Icons.add),
        ));
  }
}

[0.4.3] - 2018-10-03

  • Connect accepts null values by the explicit set of the nullable attribute.

[0.4.2] - 2018-08-06

  • Added @required annotations.

example/lib/main.dart

import 'package:flutter/material.dart' hide State;
import 'package:flutter_redurx/flutter_redurx.dart';

class State {
  State({this.title, this.count});
  final String title;
  final int count;
}

class Increment extends Action<State> {
  @override
  State reduce(State state) =>
      State(title: state.title, count: state.count + 1);
}

void main() {
  final store =
      Store<State>(State(title: 'Flutter-ReduRx Demo Title', count: 0));
  runApp(Provider(store: store, child: MyApp()));
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter-ReduRx Demo',
      theme: ThemeData(primarySwatch: Colors.pink),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Connect<State, String>(
            convert: (state) => state.title,
            where: (prev, next) => next != prev,
            builder: (title) {
              print('Building title: $title');
              return Text(title);
            },
          ),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('You have pushed the button this many times:'),
              Connect<State, String>(
                convert: (state) => state.count.toString(),
                where: (prev, next) => next != prev,
                builder: (count) {
                  print('Building counter: $count');
                  return Text(count,
                      style: Theme.of(context).textTheme.display1);
                },
              ),
            ],
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () => Provider.dispatch<State>(context, 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:
  flutter_redurx: ^0.4.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter 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_redurx/flutter_redurx.dart';
  
Version Uploaded Documentation Archive
0.4.3 Oct 4, 2018 Go to the documentation of flutter_redurx 0.4.3 Download flutter_redurx 0.4.3 archive
0.4.2+1 Sep 6, 2018 Go to the documentation of flutter_redurx 0.4.2+1 Download flutter_redurx 0.4.2+1 archive
0.4.2 Sep 6, 2018 Go to the documentation of flutter_redurx 0.4.2 Download flutter_redurx 0.4.2 archive
0.4.1+5 Aug 20, 2018 Go to the documentation of flutter_redurx 0.4.1+5 Download flutter_redurx 0.4.1+5 archive
0.3.1+5 Aug 8, 2018 Go to the documentation of flutter_redurx 0.3.1+5 Download flutter_redurx 0.3.1+5 archive
0.2.1+3 Aug 3, 2018 Go to the documentation of flutter_redurx 0.2.1+3 Download flutter_redurx 0.2.1+3 archive
0.2.1+1 Aug 3, 2018 Go to the documentation of flutter_redurx 0.2.1+1 Download flutter_redurx 0.2.1+1 archive
0.2.0 Jul 27, 2018 Go to the documentation of flutter_redurx 0.2.0 Download flutter_redurx 0.2.0 archive
0.1.0 Jul 27, 2018 Go to the documentation of flutter_redurx 0.1.0 Download flutter_redurx 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
78
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
85
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

The description is too short. (-20 points)

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
flutter 0.0.0
redurx ^0.3.0+11 0.3.0+12
Transitive dependencies
collection 1.14.11
meta 1.1.6
rxdart 0.18.1
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test