Right way or difference between using setState and streamBuilder in flutter - flutter

I want to know, when we should should use streamBuilder and when we should use setState method. Should we use only one way in the project for one code style or we can use are both ways.
For example, we have radio buttons. We can handle it and to redraw after changing radio button via streamBuilder and via setState, but what way is more useful?

Related

how to send a data from page to another without change the screen?

i have a page named displayData . On it there is a button if i click on it it shows DraggableScrollableSheet normally it has a button done when i click on it the icon of the page on the bakground (DisplayData) must change .i used a variable in a setState but it doesn't work it's true on the DraggableScrollableSheet but always false in display data
any help !
for this type of cases, there are several solutions, I recommend the use of providers, in this way with the use of 'extends ChangeNotifier' you will be able to detect the changes made without having to use the setState and you will be able to call from any class (or page ) the variables you need
you can use callback methods from on widget to another, if you have much complicated scenario then I suggest using state management libraries like Provider, RiverPod or Bloc.
also
Could you share your code here

How to simulate device back btn press/ AppBar back press? WillPopScope is not called upon Navigator.pop()

I was able to override the back button onPressed behavior using WillPopScope. Now, whenever I press the device back button or the default AppBar back button, the code inside onWillPop runs as expected.
The problem now is that I want to have my own custom buttons to navigate backward, but Navigator.of(context).pop() doesn't check the WillPopScope as if it doesn't exist.
Is there a way to simulate the system's back behavior or call it somehow?
I know I can just call the same function that is called by
onWillPop() manually upon pressing my custom back button, but I was eager to find a cleaner method, as in the future I could easily forget doing that and cause bugs.
In simple cases, when you need to intercept the Android back-button, you usually add WillPopScope to your widget tree. However, when developing stateful widgets that interact with the back button, it's more convenient to use the BackButtonInterceptor.
For more details check this link: https://pub.dev/packages/back_button_interceptor
While using StateFullWidget, It is more convenient to use BackButtonInterceptor.
Hope this will Helpful.
For more Details Please check this:
[1]: https://pub.dev/packages/back_button_interceptor
The key was to use Navigator.of(context).maybePop()instead. Or more specifically in my case, was to use Navigator.of(context, rootNavigator:true).maybePop() as I was using nested Navigation.

How to update list view without refreshing in Flutter

How can it update a list view elements without doing pull-to-refresh
If I'm adding an element in a dialog window or from an Api, how to add/update the list view elements automatically.
Should I use StreamBuilder?
Use state management pub like Getx, or something with adlistener.
Yes you can use stream builder and you can also use setstate
setState(() { });
StreamBuilder Widget builds itself based on the latest snapshot of interaction with a Stream. Thus the state of the app changes whenever new elements are added in the list as long as the connection status is active.
You can also use the combination of ListView Builder and setState method, though the state of the app needs to change whenever a new element is added. Earlier StreamBuilder widget was updating the state of the app. Various methods like adding a button to the screen, which can help the user manually change the state; can be used depending on the use case.
You can read more about it from the official docs: setState method
StreamBuilder
This answer is not exactly about updating listView, but updating a widget(PiChart). As listview is also a widget, the implementation will be the same to update without refreshing.
In this method, I am using streamBuilder to update the widget. so need not refresh the app to update the data.
https://stackoverflow.com/a/69800324/13577765

Binding data from API to gridview in Flutter on button click?

How can I Bind data from API to gridview in Flutter on button click?
Lets say I have a search button that calls a search API, after I press search I will receive a JSON response, after that I need to show it on a gridview.
The API call is most likely going to come back through a Future, so the simplest is to use a FutureBuilder. But if you can follow it, I'd use a RiverPod FutureProvider, because it will cache the results and also has this cool .when thing that eliminates the need for a FutureBuilder.

Changing multiple buttons type in flutter

I created an application in flutter where I put Raisedbutton's everywhere. I want to change them all in Neumorphicbutton. Is there a way to change all Raisedbutton's into NeummorphicButton without editing one by one?
Thank you.
You can use refactor tool to change all occurrence of Raisedbutton to Neumorphicbutton. If u want to change all of them at once
Assuming that you want all the buttons to change into a neumorphic button style by clicking a single button , you can use the Onpressed() function and have it call SetState , in which you can change each and every button to Neumorphic style