I Have a form to get data from the user. The objective is to pass the form data as an object to the Api. The Form is as follows.
Form(
key: _formKey,
child: Column(
children: [
Seperator(),
TextField(
decoration: const InputDecoration(
hintText: 'Add a title',
),
),
Seperator(),
TextField(
decoration: const InputDecoration(
hintText: 'Add a description',
),
),
Seperator(),
TextField(
decoration: const InputDecoration(
hintText: 'Add a Price',
),
),
Seperator(),
TextField(
decoration: const InputDecoration(
hintText: 'Select Unit',
),
),
Button(
isProcessing: isProcessing,
name: 'Create Post',
onPressed: () {
final formdata = _formKey.currentState!.save();
createpost(formdata); // Api Function
},
]
// Api Function
createpost(AddPost formdata) async {
try {
final service = PostService();
final response =
await service.createpost(formdata);
} catch (error) {
setErrorMessage(error.toString());
}
How can I pass the Form data as an object to the Api Function?