我正在尝试在颤动中使用 firebase 实现电话身份验证。但是,在设置用户名时遇到问题。由于用户名为空,应用无法运行。
当我使用电话号码注册时,我在 firebase 控制台的身份验证菜单中看到用户,但是,firestore 不会为用户创建记录。
这里是流程:
Phone icon button press 显示电话输入的警报对话框,otp 被发送到电话号码,输入 otp 后,显示用户名的警报对话框。一旦用户输入用户名并按下确定按钮,我就会收到错误消息:
#create the dataframe
df = pd.DataFrame(None, columns= ['Event', 'Measure', 'Measure2'])
df.loc[len(df)] = ['A', 10, 5]
df.loc[len(df)] = ['B', 11, 7]
df.loc[len(df)] = ['C', 15, 8]
df.loc[len(df)] = ['D', 21, 6]
df.loc[len(df)] = ['E', 3, 4]
print(df)
#get the new dataframe
newdf = df
newdf[['Measure', 'Measure2']] -= newdf[newdf['Event'] == 'C'][['Measure', 'Measure2']].to_numpy()[0]
newdf
这是警报对话框代码:
Exception caught by gesture ============================================
The following NoSuchMethodError was thrown while handling a gesture:
The method 'registerUser' was called on null.
Receiver: null
Tried calling: registerUser(Instance of 'StatelessElement', "handuh")
register_view_model 类 registerUser 方法:
showAlertDialog(BuildContext context) async {
RegisterViewModel viewModel;
TextEditingController textFieldController = TextEditingController();;
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(Languages.of(context).mustUsername),
content: TextField(
controller: textFieldController,
textInputAction: TextInputAction.go,
keyboardType: TextInputType.name,
decoration: InputDecoration(hintText: Languages.of(context).username),
onChanged: (String val) {
setState(() {
viewModel.setName(val);
});}
),
shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(40.0))),
actions: <Widget>[
new TextButton(
child: new Text(Languages.of(context).done),
onPressed: () {
viewModel.registerUser(context, textFieldController.text);
Navigator.pushAndRemoveUntil(context,
MaterialPageRoute(builder: (context) => TabScreen()),
(route) => false);
}
)
],
);
}
);
}
setName 方法:
registerUser(BuildContext context, String username) async {
if ((username != null) && (phone.isNotEmpty)) {
loading = true;
notifyListeners();
try {
bool success = await auth.createUser(
name: username,
phone: phone,
);
print(success);
if (success) {
Navigator.of(context).pushReplacement(
CupertinoPageRoute(builder: (_) => ProfilePicture()));
}
} catch (e) {
loading = false;
notifyListeners();
print(e);
showInSnackBar(context,
'${auth.handleFirebaseAuthError(e.toString())}');
}
loading = false;
notifyListeners();
} else {
showInSnackBar(context, Languages.of(context).errorOcc);
}
}
非常感谢帮助!