Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use callback function with value in flutter?

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?

like image 643
Daniel Mana Avatar asked May 02 '26 12:05

Daniel Mana


1 Answers

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.

like image 125
Luke Avatar answered May 07 '26 17:05

Luke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!