i'm brand new to Flutter.
I'm trying to open a panel pressing a button and than closing it by pressing a button on that panel.
I've managed to do it by writing the code in the same page.
What i can't do is splitting the code and keep everything working.
What I'm actually doing is calling a variable in the State of a widget that is initialized False and then with an if statement i'm calling: or an empty container or the panel i want.
When i press the button i call SetState(){} and the variable changes to true to let the panel appears, then in the panel there's button that do opposite thing.
Assuming that what i'm doing it is correct. How to i keep doing this with the panel refactored in a new page?
I've red something about streams and inherited widgets but i haven't completely understood
If you want to open an dialog (instead of what you call a "panel") you can simply give the selected data back when you close the dialog again. You can find a good tutorial here: https://medium.com/@nils.backe/flutter-alert-dialogs-9b0bb9b01d28
If I understand correctly, you want to notify a
StatefullWidget
from anotherStatefullWidget
. There are several approaches on this one but since you've mentionedStreams
, I'll try to post an example and explain a bit this scenario.So basically, you can consider the streams like a pipe linked to a faucet in one end and the other end it's added into a cup (the end can be split in multiple ends and put in multiple cups, "broadcast streams").
Now, the cup is the listener (subscriber) and waits for water to drop trough the pipe.
The faucet is the emitter, and it will emit water droplets when the faucet is opened.
The faucet can be opened when the other end is put into a cup, this is a smart faucet with some cool sensors, (the emitter will start emitting events when a subscriber is "detected).
The droplets are actual events that are happening in the the app.
Also you must remember to close the faucet in order to avoid a massive leak from your cup into the kitchen floor. (you must cancel the subscribers when you've done handling events to avoid a leak).
Now for your particular case here's the code snippet that kind of illustrate the above metaphor:
I hope that my analogy will help you understand a bit the streams concept.
you can navigate and return data from another screen like that :
for more details about navigation: https://flutter.dev/docs/cookbook/navigation/returning-data