Problem when i try to get the value of a function in Flutter/dart

53 views Asked by At

Hi i cant not get the value of de value that return my function postTest()

                           String usuario = usernameController.text;
                                  print('Si $usuario');
                                  String password = passwordController.text;
                                  print('Password: $password');

                                  print("${postTest(usuario, password)}");
                                }
                              },
                            ),
                            Registrate(),
                          ],
                        ),
                      ),
                    ),
                  ),
                ),
              ),
              Container(
                padding: EdgeInsets.only(top: 500, left: 170),
                child: ImagenAmbulancia(),
              )
            ],
          ),
        ),
      ),
    );
  }

  postTest(usuario, password) async {
    final uri = 'http://10.0.2.2:5000/base/';

    http.Response response = await http
        .post(Uri.parse(uri), body: {"User": usuario, "Pass": password});
    var repuesta = response.body;
    String estadoUsuario = jsonDecode(repuesta)["respuesta"];
    return estadoUsuario;
  }
}

i try to save the value that get me postTest but i cant ... return me Future , but i want the string

1

There are 1 answers

0
aliloriamini On

when you want to use your method, because its future type (and will be fill in future) you should use .then when you call your method like this

postTest(usuario, password).then((value) {
 print(value);
});