You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+46-25
Original file line number
Diff line number
Diff line change
@@ -4,33 +4,41 @@
4
4
5
5
A set of utilities that allow you to easily consume a [Redux](https://pub.dartlang.org/packages/redux) Store to build Flutter Widgets.
6
6
7
-
This package is built to work with [Redux.dart](https://pub.dartlang.org/packages/redux).
7
+
This package is built to work with [Redux.dart](https://pub.dartlang.org/packages/redux).
8
+
8
9
## Redux Widgets
9
10
10
11
*`StoreProvider` - The base Widget. It will pass the given Redux Store to all descendants that request it.
11
12
*`StoreBuilder` - A descendant Widget that gets the Store from a `StoreProvider` and passes it to a Widget `builder` function.
12
13
*`StoreConnector` - A descendant Widget that gets the Store from the nearest `StoreProvider` ancestor, converts the `Store` into a `ViewModel` with the given `converter` function, and passes the `ViewModel` to a `builder` function. Any time the Store emits a change event, the Widget will automatically be rebuilt. No need to manage subscriptions!
13
14
15
+
## Dart Support
16
+
17
+
* Dart 1: 0.3.x
18
+
* Dart 2: 0.4.0+. See the migration guide below!
19
+
14
20
## Examples
15
21
16
22
*[Simple example](https://gitlab.com/brianegan/flutter_redux/tree/master/example) - a port of the standard "Counter Button" example from Flutter
17
-
*[Todo app](https://gitlab.com/brianegan/flutter_architecture_samples/tree/master/example/redux) - a more complete example, with persistence, routing, and nested state.
18
-
23
+
*[Todo app](https://gitlab.com/brianegan/flutter_architecture_samples/tree/master/example/redux) - a more complete example, with persistence, routing, and nested state.
24
+
19
25
## Usage
20
26
21
27
Let's demo the basic usage with the all-time favorite: A counter example!
22
28
29
+
Note: This example requires flutter_redux 0.4.0+ and Dart 2! If you're using Dart 1, [see the old example](https://github.com/brianegan/flutter_redux/blob/eb4289795a5a70517686ccd1d161abdb8cc08af5/example/lib/main.dart).
// Attach the `callback` to the `onPressed` attribute
108
122
onPressed: callback,
109
123
tooltip: 'Increment',
110
-
child: new Icon(Icons.add),
124
+
child: Icon(Icons.add),
111
125
),
112
126
),
113
127
),
@@ -117,7 +131,14 @@ class FlutterReduxApp extends StatelessWidget {
117
131
}
118
132
```
119
133
120
-
### Purpose
134
+
## Dart 2 Migration
135
+
136
+
Dart 2 requires more strict typing (yay!), and gives us the option to make getting the Store from the StoreProvider more convenient!
137
+
138
+
1. Change `new StoreProvider(...)` to `StoreProvider<StateClass>(...)` in your Widget tree.
139
+
2. Change `new StoreProvider.of(context).store` to `StoreProvider.of<StateClass>(context)` if you're directly fetching the `Store<AppState>` yourself from the `StoreProvider<AppState>`. No need to access the `store` field directly any more since Dart 2 can now infer the proper type with a static function :)
140
+
141
+
## Purpose
121
142
122
143
One question that [reasonable people might ask](https://www.reddit.com/r/FlutterDev/comments/6vscdy/a_set_of_utilities_that_allow_you_to_easily/dm3ll7d/): Why do you need all of this if `StatefulWidget` exists?
0 commit comments