Comments (14)
Yep! You can also see this technique in the example on the README of this package as well. Another option: If your action is static, you can also forego the StoreConnector
by accessing the StoreProvider
yourself:
StoreProvider.of<AppState>(context).dispatch(Actions.increment)
The StoreConnector
is responsible for connecting to the Store and rebuilding on change. Since this function would not change, no need for the connector / rebuilding!
from flutter_redux.
Ha! I forgot that is still up there! I actually wrote it and still use it some days when I need a little zen but...the code is SO bad (I was learning js at the time) that I would like to update just a little before anyone else sees it...I'll update and upload the code sometime next few months and I will let you know :-)
from flutter_redux.
The example at http://blog.novoda.com/introduction-to-redux-in-flutter/ indicates that the methods should be added to the model then the model called which then has access to the store - is this the correct design?
from flutter_redux.
Hi, I just tried this out actually but I'm getting a syntax error on the <AppState>
generic type.
[dart] Expected to find ';'
new RaisedButton(child:new Text('load2'), onPressed: () {
StoreProvider<AppState>.of(context).dispatch(lessonsLoadFsAction);
})
from flutter_redux.
Ack, sorry about that, shouldn't code in Github :P
It's StoreProvider.of<AppState>(context).dispatch(lessonsLoadFsAction)
from flutter_redux.
Thanks Brian for the quick response, unfortunately I'm getting a new error now
[dart] The method 'of' isn't defined for the class 'StoreProvider', but a constructor with that name is defined.
I'm using dart 1 with the following versions
redux: ^2.1.1
flutter_redux: ^0.3.6
redux_thunk: 0.1.1
if I run it using dart 2 (flutter run --preview-dart-2
) with the following versions
redux: ^3.0.0
flutter_redux: ^0.5.0
redux_thunk: 0.2.0
I get the runtime message when it hits any redux code:
- Using Dart 2 (required) by using the --preview-dart-2 flag
- Wrapping your MaterialApp with the StoreProvider, rather than an individual Route
- Providing full type information to your Store, StoreProvider
(I was going to update to flutter master, currently on 0.2.3 but it wasn't immediately obvious how to...let me know if its worth a try)
from flutter_redux.
Updating to master version worked for me. Many thanks
btw, if anyone wants to know how to set dart 2 in vs code (required for debug) the setting to do this (ctrl + ,)
"dart.previewDart2": true,
from flutter_redux.
@twistedinferno Hah, ya beat me to it :) Yah, there seems to be a Dart 2 bug on Beta channel that only affects some users. Sorry bout that!
from flutter_redux.
p.s. This needs to be a thing: https://github.com/twistedinferno/yoda-motivator
from flutter_redux.
btw, I am calling dispatch in the build function of my widget to load some data (I don't want it loaded when redux initialises as it is not always necessary and may take time), would you say this is a good location for it?
class SplashS extends StatelessWidget {
@override
Widget build(BuildContext context) {
StoreProvider
.of<AppState>(context)
.dispatch(lessonsLoadFsAction);
return new Scaffold(
body: new Container(
child: new Column(
from flutter_redux.
@twistedinferno I would say it's probably not the best place, because the build
method can be called many times, and it would result in fetching the data over and over. If you only need to load the data once, you have two options:
- In the
StoreConnector
widget that needs the data, you can provide anonInit
callback to dispatch this action. - Use a
StatefulWidget
instead, and dispatch the action in theinitState
method, this can be a bit trickier though
from flutter_redux.
Thanks again Brian, I'll try that out :-)
from flutter_redux.
@Paul-Todd Hey there -- did I answer your question? Need more help? Happy to keep this open if so, or close out if you're feeling good.
from flutter_redux.
Thanks, you that did it - moved all my methods to the model and it hangs together nicely!
I will try the StoreProvider.of() stuff when I get the chance as this looks like a nice way to do it as well.
from flutter_redux.
Related Issues (20)
- The value 'null' can't be assigned to a variable of type 'ViewModel' because 'ViewModel' is not nullable.
- Receive the action that caused the state update in StoreConnector hooks
- [Question]: Mixing global and local state
- How to not accept change notifications when the Router is not at the top level, and then take the initiative to obtain the changes when the Router returns to the top level HOT 1
- onDidChange called twice HOT 8
- Is this package still actively maintained?
- `onWillChange` and `onDidChange` errors are swallowed HOT 4
- Warning related to `?` operator on Linux/Dev channel. HOT 2
- Import Store data type
- Widgets binding error after upgrading flutter version to 2.13.0-0.1.pre HOT 1
- onDidChange not working as expected HOT 3
- Build warning with Flutter 3.0 HOT 5
- flutter_redux depends on flutter_redux, version solving failed HOT 3
- onWillChange and onDidChange called twice after state update HOT 2
- Passing Store as an argument to MethodChannel and Background Isolate
- Question on how to use the reducer right way HOT 2
- [Question]: Any thoughts on difference between ignoreChange and distinct?
- Socket and Flutter_redux HOT 18
- Dispatching an action that does not alter state rerenders the widget, causing an infinite loop HOT 5
- How to watch redux store change inside useEffect? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_redux.