flutter - 无法从异步函数访问函数参数
问题描述
在注册的那一刻,当我尝试打印作为函数参数的用户名时,它不会在屏幕上打印任何内容,我不明白为什么。
Future registerWithEmailAndPassword(String username, String email, String password) async {
try {
AuthResult result = await _auth.createUserWithEmailAndPassword(email: email, password: password);
FirebaseUser user = result.user;
// create a new document for the user with the uid
print(username);
await DatabaseService(uid: user.uid).updateUserData(username);
return _userFromFirebaseUser(user);
} catch (error) {
print(error.toString());
return null;
}
}
编辑:这是调用 registerWithEmailAndPassword 函数的函数:
onPressed: () async {
if (error.length > 0)
error = "";
if (_formKey.currentState.validate()) {
setState(() => loading = true);
dynamic result = await _auth.registerWithEmailAndPassword(username, email, password);
if (result == null){
if (this.mounted){
setState(() {
error = 'Please supply a valid email';
loading = false;
});}
}
}
}
解决方案
推荐阅读
- javascript - 使用数组索引重新排序后获取两个数组之间的状态
- google-cloud-platform - 谷歌云平台修复 SSH
- .net-core - 是否可以为 dotnet watch 命令添加延迟?
- r - 如何在同一图表上绘制多条线?
- python - 如何在 Django 休息框架中将 DateTime 过滤为空?
- c# - 无法加载 DLL 'onnxruntime' 或其依赖项之一 ML.NET
- r - R从data.table列中提取字符串
- android - android webview下方不需要的空格
- snakemake - 如何读取 config.yaml 文件并将其输入到 snakemake
- javascript - 将多个脚本标签附加到在 React 中同步执行的头部