Callback from a custom widget

I've just been playing around with a custom widget from pub.dev as a practice in using custom widgets. I specifically wanted to see how to pass data back from a custom widget. I remembered there is an action of type Execute Callback so I thought that would be used. When I tried to use it, it is only available if the callback has a parameter which seemed reasonable as I was trying to pass back one or more parameters from my custom widget.

I tried to define my callback in the custom widget code to have a parameter but when I tried that it would fail to compile but did not have any error messages shown. The only way I could fix that was to remove the parameter from the callback.

I then started looking at the FlutterFlow docs for callbacks in Custom Widgets and it looks like the callback is just to invoke an action and the values to pass back must be placed in AppState variables. The usual thing seems to be to select Update AppState as the action but not select a variable. Just select Rebuild Current Page to force it to update with the changed AppState variable. Not sure yet if a DataType can be used to pass back multiple values in an object.

Can anyone confirm if my understanding is correct and whether this is to be enhanced so the callback will be able to take parameters? I suppose the complication will be, how will an action access those parameters.

Just tested and you can use an AppState variable as a DataType (object) and so can pass back multiple values from a custom widget. Where "pass back" means passing back via AppState of course.

3
10 replies