单击注册页面时,它不会导航到主页。而且数据库不会自动创建。尽管在身份验证页面中出现了列表。正在注册。
//signuppage.dart
onPressed: (){
var createUserWithEmailAndPassword = FirebaseAuth.instance.createUserWithEmailAndPassword(
email: _email,
password: _password);
createUserWithEmailAndPassword.then((signedInUser){
UserManagement().storeNewUser(signedInUser, context);
}).catchError((e){
print(e.toString());
});
},
这是usermanagement.dart
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/widgets.dart';
class UserManagement {
storeNewUser(user, context) {
Firestore.instance.collection('/users').add({
'email': user.email,
'uid': user.uid
}).then((value) {
Navigator.of(context).pop();
Navigator.of(context).pushReplacementNamed('/homepage');
}).catchError((e) {
print(e);
});
}
}
应用运行此错误消息时
I/flutter ( 1507): NoSuchMethodError: Class 'AuthResult' has no instance getter 'email'.
I/flutter ( 1507): Receiver: Instance of 'AuthResult'
I/flutter ( 1507): Tried calling: email
面对此问题无法将数据存储到Firebase云
答案 0 :(得分:2)
身份验证的结果是AuthResult,而不是FirebaseUser。
要将用户传递给您的功能,您应该发送now := time.Now()
diff := now.Sub(t)
fmt.Printf("Lifespan is %f", diff.Hours())
而不是signedInUser.user
我建议您仔细阅读文档,因为这会非常棘手。
希望对您有帮助!
编辑:
我还建议设置函数中使用的变量的类型,这样您的IDE会在键入时指出错误。
例如,您应该更改
signedInUser
进入
storeNewUser(user, context)