问题描述
嗨,我无法获得返回我的函数 posttest() 的 de 值
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;
}
}
我尝试保存让我得到 postTest 的值,但我不能......返回我 Future ,但我想要字符串
解决方法
当你想使用你的方法时,因为它的未来类型(将来会被填充)你应该在像这样调用你的方法时使用 .then
postTest(usuario,password).then((value) {
print(value);
});