【发布时间】:2020-03-28 23:21:41
【问题描述】:
所以我在我的应用上有一个 facebook 登录,我想将用户信息、姓名和照片发送到我的 Firebase。我能够使用“displayName”和“photoUrl”检索此信息,但是当我尝试上传到“用户”数据库时,它不会创建集合。你们知道我该怎么做吗?
class ConfAuthScreen extends StatelessWidget {
FirebaseUser _currentUser;
ConfAuthScreen(this._currentUser);
Future<FirebaseUser> addData() async {
if (_currentUser != null) return _currentUser;
Firestore.instance.collection('users').add(
{'name': _currentUser.displayName, 'photo': _currentUser.photoUrl});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.deepPurple,
body: Center(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: 150.0,
width: 150.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(_currentUser.photoUrl))),
),
Padding(
padding: const EdgeInsets.only(top: 30.0),
child: Text(
"Bem vindo(a) ${_currentUser.displayName}",
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
textAlign: TextAlign.center,
),
),
SizedBox(
height: 15.0,
),
RaisedButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => ChatScreen(_currentUser)));
},
child: Text(
"OK",
style: TextStyle(color: Colors.black),
))
])),
),
);
}
}
【问题讨论】:
标签: firebase flutter firebase-authentication