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
+43-23Lines changed: 43 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -5,13 +5,18 @@
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
7
This package is built to work with [Redux.dart](https://pub.dartlang.org/packages/redux).
8
-
8
+
9
9
## Redux Widgets
10
10
11
11
*`StoreProvider` - The base Widget. It will pass the given Redux Store to all descendants that request it.
12
12
*`StoreBuilder` - A descendant Widget that gets the Store from a `StoreProvider` and passes it to a Widget `builder` function.
13
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!
14
14
15
+
## Dart Support
16
+
17
+
* Dart 1: 0.3.x
18
+
* Dart 2: 0.4.0+. See the migration guide below!
19
+
15
20
## Examples
16
21
17
22
*[Simple example](https://gitlab.com/brianegan/flutter_redux/tree/master/example) - a port of the standard "Counter Button" example from Flutter
@@ -26,17 +31,19 @@ This package is built to work with [Redux.dart](https://pub.dartlang.org/package
26
31
27
32
Let's demo the basic usage with the all-time favorite: A counter example!
28
33
34
+
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
114
127
onPressed: callback,
115
128
tooltip: 'Increment',
116
-
child: new Icon(Icons.add),
129
+
child: Icon(Icons.add),
117
130
),
118
131
),
119
132
),
@@ -123,7 +136,14 @@ class FlutterReduxApp extends StatelessWidget {
123
136
}
124
137
```
125
138
126
-
### Purpose
139
+
## Dart 2 Migration
140
+
141
+
Dart 2 requires more strict typing (yay!), and gives us the option to make getting the Store from the StoreProvider more convenient!
142
+
143
+
1. Change `new StoreProvider(...)` to `StoreProvider<StateClass>(...)` in your Widget tree.
144
+
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 :)
145
+
146
+
## Purpose
127
147
128
148
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