Is there any way how to reload all FutureBuilders? - flutter

Is there any way how to reload all FutureBuilders in application without need to change every futurebuilder?

Yes, there is. Just call setState((){}) in the tree (or subtree) that has all the FutureBuilders and make sure that the future property calls the future method directly, for example. The build method should trigger a new call to the future.

Related

addPostFrameCallback vs scheduleFrameCallback

So, I was wondering, when to use WidgetsBinding.instance.addPostFrameCallback and WidgetsBinding.instance.scheduleFrameCallback for setState, as according to the documentation, the first one doesn't initiate a frame on its own, while if we asynchronously call setState then it might get called during the build of another widget, which can cause not to update the other widget, so for it, we add it as a "post frame" callback, but if it is called not during a build, then it will not initiate the next frame on its own, i.e we cannot always wrap async setState calls with it, as there is a good chance it might be called during not a build, that's when I found scheduleFrameCallback, and according to its documentation, I think it schedules the next frame and adds its as a callback to it, i.e it also initiates a frame. So is it always better to call setState inside it, or is it something else?

where to write logic for every widget in flutter?

I know this is a basic question but I wanna know how you guy's implement logic for your widgets. I normally write logic in build() function just above the return type.
What do you mean by logic..?? If you are talking about like adding some values.. then we use a different method for that outside the build Method because build method will rebuild when the set state method called so some times logic can be used inside the build but some time we need to write the logic in different method and called them..
Build method will rebuild every time the app state got change or refresh
if you talking about widget state
You can write it in separate file using state management approaches like (Getx,Provider)
You can write it in separate function if you need to perform setState that method will update the state
...Try to use separate functions and controllers for logic it will help you in scalability for your code
If you write your logic in build method means it will rebuild every time when the page is refreshed.
I will suggest you to follow MVVM(Model View ViewModel) architecture, so that all the business logics can be written in controllers (ex: cart_controller.dart) .So that your files are separated from actual widgets.
UI goes into - cart_page.dart,
Logic goes into - cart_controller.dart

What are dependencies of a state in flutter

I am trying to understand the method didChangeDependencies and according to the definition
It is Called when a dependency of this State object changes.
what do they mean by this. My guess is when properties in the state you manage per screen change. Am I right. Please I would love to understand better.
Try to think of it the same as initState but just a little later.
initstate is called before the state loads its dependencies and for that reason no context is available and you get an error for that if u use context in initstate. However, didChangeDependencies is called just few moments after the state loads its dependencies and context is available at this moment so here you can use context.
In case BuildContext.dependOnInheritedWigetOfExactType called, or in case the widget is been moved inside of the element tree, didChangeDependencies will is always called.

How to call a method from InheritedWidget only once?

I'm developing with reactive components streams/observables with Rx_command, Rx_dart
Problem:
In my Flutter app I have inherited widget that can be called anywhere with:
FooProvider.of(context).foo.method1...
I need to make a first call to the method when the UI loads at first time
I can't use init.state because it's impossible
I use didchangedependencies it works but..
... every time the ui reloads, the didchangedependencies is called and the method is executed once again.
I don't want it to be executed and I can't use init.state
How can execute the method only once?
Instead of context.inheritFromWidgetOfExactType, use context.ancestorInheritedElementForWidgetOfExactType
final myInherited = context.ancestorInheritedElementForWidgetOfExactType(MyInherited)?.widget;
This method is available inside initState

React Native: what lifecycle should I look for when I want to refresh ListView whenever I navigate back to it?

Pretty much like the official tutorial here https://facebook.github.io/react-native/docs/tutorial.html:
I have the fetchData method called in ComponentDidMount, but according to this, ComponentDidMountwould only be called once after initial rendering of the component. So should I do call the same fetchData everytime before I navigate back to this ListView, and pass the updated data as props to the ListView, and then update the listView's state parameter accordingly in componentDidUpdate? Or is there any better way to do this?
You should register an event listener on componentDidMount and unregister it on componentWillUnmout, and emit events whenever and wherever you change the data your component displays.
Good rundown of this pattern here: https://colinramsay.co.uk/2015/07/04/react-native-eventemitters.html