Comments (6)
It looks like your view model is missing the required equality functions to be able to utilize the distinct property.
From the flutter_redux.dart file:
/// As a performance optimization, the Widget can be rebuilt only when the
/// [ViewModel] changes. In order for this to work correctly, you must
/// implement [==] and [hashCode] for the [ViewModel], and set the [distinct]
/// option to true when creating your StoreConnector.
from flutter_redux.
Hey hey :) Thanks for writing in! One option that might work well for this case is to pass an onWillChange
callback to the StoreConnector. This will let you run a function after the Store has changed, and is meant to handle situations like this.
Please feel free to try that, and if it doesn't quite work please write back and we can think of more options :)
from flutter_redux.
Thanks! @brianegan I tried the onWillChanged function and it works, I just have a problem with checking the exact change on the Store. So the body of the function won't run on every state change. Trying to check for the change in the state.isLoginFailed
variable.
from flutter_redux.
Cool, glad that worked for ya.
To solve the second challenge, one solution is to use the distinct
property on the StoreConnector. If the ViewModel does not change (based on it's ==
method), it won't re-run the onWillChange
function!
from flutter_redux.
Hi @brianegan Noticed that you closed the issue. I'm sorry for the late responses but, I don't understand how setting the distinct property to true will help me in this case. Here's my storeConnector:
_ViewModel _viewModel = new _ViewModel(context: context);
// String isLoginFailed;
return new StoreConnector<AppState, _ViewModel>(
onInit: (Store<AppState> store){
// isLoginFailed = store.state.isLoginFailed;
},
onWillChange: (_viewModel){
Scaffold.of(context).showSnackBar(new SnackBar(
content: new Text("Error Occurred")));
},
distinct: true,
converter: _viewModel.fromStore,
builder: (BuildContext context, _viewModel){
return new LoginForm(
email: _viewModel.email,
password: _viewModel.password,
saveEmail: _viewModel.saveEmail,
savePassword: _viewModel.savePassword,
attemptLogin: _viewModel.attemptLogin,
);
}
);
Where am I supposed to perform the check if the state.isLoginFailed
variable has changed?
Everything inside onWillChanged works but the snackBar shows everytime my state changes
from flutter_redux.
I had somewhat the same problem. I decided to make a "ErrorSnackbar" widget which listens for changes on the state.error variable, displays them in a snackbar and then clears up the variable.
I ended up with this code: https://gist.github.com/ScholliYT/d26dc1b947ff48eb0c96bc7c6d4e086e
I think it's bad practice to just return an empty Text widget but I could not figure out how to do it better and this seems to work.
Just add the Widget to your Scaffold like this:
body: Stack(
children: <Widget>[
// put other stuff here...
ErrorSnackbar(),
],
),
from flutter_redux.
Related Issues (20)
- 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
- [Question] is it expected that the store doesn't run until frames render? HOT 1
- After push a new page, and Dispatching an action, there is an infinite loop
- Is flutter redux actively maintained HOT 1
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.