flutter - 当我尝试在 Flutter/dart 中获取函数的值时出现问题
问题描述
嗨,我无法获得返回我的函数 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);
});
推荐阅读
- wordpress - 在 wordpress 中评分和评论
- javascript - react fetch javascript 上传视频 nodejs multer
- teamcity - 将构建和部署信息添加到 JIRA
- javascript - socketio 无法创建空间
- r - 闪亮的数字输入 - 添加计算
- python - TypeError Python:字符串索引必须是整数
- javascript - 较大对象中的 this.objectName 在执行期间变得未定义
- c++11 - < 操作的行为类似于 <= 对于双变量的特定值
- c - 更改符号后,我的代码停止工作
- arduino - 如何使arduino使用RS232串口在2个设备之间进行通信?