【发布时间】:2020-12-19 01:42:08
【问题描述】:
我无法从 Firestore 中检索数据并出现如下错误,
════════ 小部件库捕获的异常 ══════════════════════════════════════════════════ ═════以下 断言被抛出构建 StreamBuilder(dirty, 状态:_StreamBuilderBaseState
#e568b): 构建函数返回 null。 有问题的小部件是:StreamBuilder 构建函数 绝不能返回 null。
返回导致建筑小部件填充的空白空间 可用空间,返回“Container()”。返回一个空白空间 占用尽可能少的空间,返回 "Container(width: 0.0, 高度:0.0)"。
相关的导致错误的小部件是:StreamBuilder file:...dart:140:15 抛出异常时,这是堆栈:
#0 debugWidgetBuilderValue。 (包:flutter/src/widgets/debug.dart:300:7) #1 _Closure.call (dart:core-patch/function.dart) #2 debugWidgetBuilderValue (package:flutter/src/widgets/debug.dart:321:4) #3 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4569:7) #4 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4737:11) ...
下面是我的代码。
StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection("currency").snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData){
print('test pharse');
Text("Loading.....");}
else {
List<DropdownMenuItem> currencyItems = [];
for (int i = 0; i < snapshot.data.documents.length; i++) {
DocumentSnapshot snap = snapshot.data.documents[i];
currencyItems.add(
DropdownMenuItem(
child: Text(
snap.documentID,
style: TextStyle(color: Color(0xff11b719)),
),
value: "${snap.documentID}",
),
);
}
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.mail,
size: 25.0, color: Color(0xff11b719)),
SizedBox(width: 50.0),
DropdownButton(
items: currencyItems,
onChanged: (currencyValue) {
final snackBar = SnackBar(
content: Text(
'Selected Currency value is $currencyValue',
style: TextStyle(color: Color(0xff11b719)),
),
);
Scaffold.of(context).showSnackBar(snackBar);
setState(() {
selectedCurrency = currencyValue;
});
},
value: selectedCurrency,
isExpanded: false,
hint: new Text(
"Choose Currency Type",
style: TextStyle(color: Color(0xff11b719)),
),
),
],
);
}
}),
【问题讨论】:
标签: flutter google-cloud-firestore