0

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.

  • Does this answer your question? [What is a Future and how do I use it?](https://stackoverflow.com/questions/63017280/what-is-a-future-and-how-do-i-use-it) – nvoigt Jul 05 '22 at 10:06

1 Answers1

0

Use await before calling postDataLoginEmployee().

Huthaifa Muayyad
  • 11,321
  • 3
  • 17
  • 49