我正在从 Firestore 中检索一些数据,如下所示:
String _fName;
Future<dynamic>_retrieveData() async{
var firebaseUser = await FirebaseAuth.instance.currentUser();
await Firestore.instance.collection("tryingdata").document(firebaseUser.uid).snapshots().listen((DocumentSnapshot doc) async{
Map<String, dynamic> document = doc.data;
setState((){
_fName = document['firstName'];
});
print(_fName);
});
}
@override
void initState() {
// TODO: implement initState
super.initState();
_retrieveData();
}
我想在我的 TextFormField 中有一个 initialValue,但我必须使用控制器而不是 initialValue,但控制器必须是 TextEditingController 变量。但我从数据库中检索字符串。我希望数据库中的值作为初始值显示在 TextFormField 中。我收到以下错误:错误:无法将参数类型“String”分配给参数类型“TextEditingController”。
TextFormField(
controller: _fName,
textAlign: TextAlign.left,
),
谢谢你的帮助!