Reputation: 10391
I wanted to allow a class that have a callback that passes back data to the main class.
So there is two class: First class contain the body of another widget from other class and a save button. The second class is the widget class stores in another file.
How to I save the value that had been inputted in the second class after i click the save button?
Upvotes: 3
Views: 5145
Reputation: 6778
Can't you just do:
class WidgetWithCallback {
VoidCallback onButtonPressed;
ClassWithCallback(this.onButtonPressed);
...
}
If you want to apply a name to the callback then you could use:
ClassWithCallback({@required this.onButtonPressed});
Then within that widget just call the callback whenever the button is pressed or files selected, etc?
If you need to pass data back you can use a typedef
.
Upvotes: 2