Home > Mobile >  Dart/Flutter async function return -Instance of '_Future<dynamic>'
Dart/Flutter async function return -Instance of '_Future<dynamic>'

Time:07-05

I am using async Function on Dart/Flutter. I want to return a string value from function.

Map dataLoginEmployee = {
  'email': employee.getEmail(),
  'password': employee.getPassword(),
};

String bodyLoginEmployee = json.encode(dataLoginEmployee);

postDataLoginEmployee() async {
      final response = await http.post(
        Uri.parse(url),
        headers: {"Content-Type": "application/json"},
        body: bodyLoginEmployee,
      );
    
      return response.body;
    }

return response.body 's return: Instance of '_Future'

enter image description here

I am try a lot of method but they are didn't work.

  • I try use getter setter.
  • I try Future< String >, void, static, dynamic.

Please help me in a any way, Thanks.

CodePudding user response:

Use await before calling postDataLoginEmployee().

  • Related