Closed point-source closed 3 years ago
Hello @point-source,
You can implement such behaviour using the key argument of the AFWidget to access the AFWidgetState.submitForm method !
Here is a little example:
final GlobalKey<AFWidgetState> formStateKey = GlobalKey<AFWidgetState>();
@override
Widget build(BuildContext context) {
return ...(
action: SizedBox(
width: 180,
child: Button(
expanded: true,
text: campaign == null ? 'Create campaign' : 'Update campaign',
onPressed: () => formStateKey.currentState.submitForm(),
),
),
child: AFWidget(key: formStateKey, ...),
);
}
Oh man, I was so close! I tried a key but used the wrong type in the generic. 🤦
Thanks! Closing this
How can I programmatically cause the form to submit? Sometimes, I want to locate the submit button elsewhere or put something between the form and the button in such a way as a child widget would not necessarily allow. Is there a way to get a callback or provide a key so I can tell the form to submit?
Alternatively, a way to just access the current form state would be fine as well.