我正在嘗試從我的 Firebase 實時資料庫中獲取我的資料串列。我正在使用小部件 FirebaseAnimatedList 來填充和正確查詢資訊。
當我嘗試參考資料快照時,出現錯誤。對于任何 Swift / UIKit 程式員,我正在嘗試生成以下內容:
if let value = snapshot.value["name"] as? String {
print(value)
}
我嘗試在這里呼叫 snapshot.value['name'] 。然后我得到一個錯誤,我需要支持可選功能,當我添加 時?.,我得到另一個我不能的錯誤:

final FirebaseDatabase database = FirebaseDatabase.instance;
DatabaseReference _categoriesRef = FirebaseDatabase.instance
.ref()
.child("Apps")
.child(GlobalVariables.restaurantId)
.child("menu")
.child("categories");
Container(
height: 50,
child: new FirebaseAnimatedList(
scrollDirection: Axis.horizontal,
query: _categoriesRef,
padding: EdgeInsets.fromLTRB(25, 0, 25, 0),
itemBuilder: (
BuildContext context,
DataSnapshot snapshot,
Animation<double> animation,
int index,
) {
var title = snapshot.value?.["hi there"];
var titleText = "All ";
return GestureDetector(
onTap: () {
setState(() {
selectedIndex = index;
});
},
child: Container(
height: 20,
child: categoryContainer(
titleText,
"hello",
index,
),
width: getWidth(titleText) 50,
),
);
},
),
),

uj5u.com熱心網友回復:
快照的值可以有多種型別,這里似乎需要指明型別。
var value = Map<String, dynamic>.from(snapshot.value as Map);
var title = value["name"];
另請參閱:Get Map<String, dynamic> from Map<dynamic, dynamic> flutter
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/439613.html
標籤:火力基地 扑 镖 目的 firebase-实时数据库
