[英]Flutter - populating syncfusion calendar with data from Firebase
[英]Flutter populating data in DropDown from firebase
我正在學習 flutter 並按照教程從 firebase FireStore 的下拉列表中填充數據。 但在此過程中我收到錯誤:
引發了另一個異常:必須向 Text 小部件提供非空字符串。
我附上代碼,請告訴我如何解決此問題。
//Code Above
Container(
padding: EdgeInsets.all(5),
child: StreamBuilder<QuerySnapshot>(
stream: repository.getStream(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return const Center(
child: const CupertinoActivityIndicator(),
);
return Container(
padding: EdgeInsets.all(5),
child: new DropdownButton(
value: _dropdownValue,
isDense: true,
items:
snapshot.data.documents.map((DocumentSnapshot doc) {
return new DropdownMenuItem<int>(
value: doc.data["classid"] as int,
child: Text(doc.data["className"]));
}).toList(),
hint: Text("Choose Class"),
onChanged: (value) {
setState(() {
_dropdownValue = value;
});
},
),
);
},
),
),
//Code Below
我發現錯誤是從以下位置觸發的:
孩子:文本(doc.data[“className”]));
這條線,為了測試,我把它改成了Text(“Sample”),然后它在上面的那行給出了錯誤
值:doc.data["classid"] as int,
錯誤:
引發了另一個異常:應該恰好有一個項目具有 [DropdownButton] 的值:0。
第一個錯誤是說doc.data["className"]
是 null。 檢查您的 Firestore 並確保您正在加載的所有文檔在className
字段上都有值。
第二個錯誤表明您有多個文檔具有相同的doc.data["classid"]
值。 DropdownMenuItem
的每個值都必須是唯一的,因此請確保您在任何文檔中都沒有相同的classid
。
return Container( padding: EdgeInsets.all(5), child: DropdownButton( value: _chosenValue, isDense: true, items: snapshot.data..docs:map((DocumentSnapshot doc) { return DropdownMenuItem( value.doc,data[' title']: child.Text(doc;data['title'])). }),toList(): 提示, Text("Choose Category"): onChanged? (value) { setState(() { _chosenValue = value作為字符串;; }), }, ); );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.