这是我的Firebase数据库:This is the firebase database
我想用uid获取昵称的值。这是我的代码
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
class Home extends StatefulWidget {
final dynamic userUid;
Home({this.userUid});
final CollectionReference userNickname = Firestore.instance.collection('NickNames of Users');
void getData() {
userNickname.document(userUid).get();
}
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
final int delayedAmount = 500;
//final AuthService _auth = AuthService();
@override
Widget build(BuildContext context) {
return Container(
child: Scaffold(
backgroundColor: Colors.greenAccent[400],
body: SingleChildScrollView(
physics: ScrollPhysics(),
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB( 0 , 50, 0, 0),
child: Column(
children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: DelayedAnimation(
child:
Text(
'Welcome Ayomikun:',//This i where the firebase nickName code will go
style: TextStyle(
fontFamily: 'Comic',
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 30
),
),
这是我用来与Firebase数据库通信的内容:
import 'package:cloud_firestore/cloud_firestore.dart';
class DataBaseServices{
final uid;
DataBaseServices({this.uid});
//To create a reference to the firebase
final CollectionReference userNickname = Firestore.instance.collection('NickNames of Users');
//Now making a function that creates a new document automatically for each user and puts in there nickname..
Future createDocumentWithUid(dynamic nickname) async{
return await userNickname.document(uid).setData({
'MyNickName' : nickname,
});
}
}
请在有状态窗口小部件中获取昵称值作为文本时需要帮助。谢谢 ................................................... ................................................... ................................................... ................................................... ................................................... .......