Home > Net >  Function expressions can't be named: then(
Function expressions can't be named: then(

Time:06-23

Im having issues with my code and since I'm new at using Flutter, I have no clue on how to fix it. I was trying to fix the http.get(string) and I kind of did, but now I'm having issues with then(()).

void submitForm(FeedbackForm feedbackForm) async {
try {
  await http.get(Uri.parse(URL   feedbackForm.toParams()).then((response)) {
    callback(convert.jsonDecode(response.body['status']));
  });
} catch (e) {
  print(e);
}

} }

CodePudding user response:

It seems you got a parenthesis missplaced:

await http.get(...).then((response) => callback(...))

The them allows you to use the result of the previous Future, as soon as it becomes available. If you find it confusing you can declare one variable at a time.

final response = await http.get(...);
// Check if response was as expected
await callback();
  • Related