我有一個 StreamBuilder 來檢查一個空字串但我想把它變成一個空陣列。我怎樣才能做到這一點?
bool? checkEmpty = false;
StreamBuilder<DocumentSnapshot<Map<String, dynamic>>>(
stream: FirebaseFirestore.instance
.collection('widgets')
.doc(widgets)
.snapshots(),
builder: (context, snapshot) {
snapshot.data?.data()?.forEach((key, value) {
if (key == 'imageUrl') {
checkEmpty = value == [];
}
});
return ...
checkEmpty!
? Text('Array is not empty')
: Text('Empty array'),

uj5u.com熱心網友回復:
將值型別轉換為List然后檢查它。
嘗試以下操作:
bool? checkEmpty = false;
StreamBuilder<DocumentSnapshot<Map<String, dynamic>>>(
stream: FirebaseFirestore.instance
.collection('widgets')
.doc(widgets)
.snapshots(),
builder: (context, snapshot) {
snapshot.data?.data()?.forEach((key, value) {
if (key == 'imageUrl') {
checkEmpty = (value as List).isEmpty;
}
});
return ...
checkEmpty!
? Text('Array is not empty')
: Text('Empty array'),
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/522602.html
標籤:Google Cloud Collective 扑火力基地镖谷歌云火库
