我在flutter的streambuilder中得到一個錯誤。 我不確定為什么會出現這個錯誤。請幫助我解決這個問題。
Widget _galleryGrid() {
return StreamBuilder(
stream: imageUrlsController.stream,
builder: (context, snapshot) {
if ( snapshot.hasData) {
if (snapshot.data! .length != 0) {
return GridView.buildinger(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2) 。
itemCount: snapshot.data!.length,
itemBuilder。(context, index) {
return CachedNetworkImage(
imageUrl: snapshot.data![index],
適合。BoxFit.cover,
placeholder: (context, url) => Container(
對齊。Alignment.center,
孩子。圓形進度指示器()
)
);
}
);
} else {
return Center(child: Text('No images to display.' ))。
}
} else {
return Center(child: CircularProgressIndicator())。
}
}
);
}
我有紅色的下劃線,表示總共有3個部分的錯誤
如果(snapshot.data!.length !=0){itemCount: snapshot.data!.length,
imageUrl: snapshot.data![index]
uj5u.com熱心網友回復:
- 這需要啟用'non-nullable'語言功能。
- 嘗試更新你的pubspec.yaml,將最低SDK約束設定為2.12.0或更高。
- 運行'pub get'/li>
或者
用
代替這一點if (snapshot.data! .isNotEmpty) {
uj5u.com熱心網友回復:
在流的構建器中簡單地指定你的快照型別:-
builder: (context, AsyncSnapshot<QuerySnaphot> snapshot) {
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/329157.html
標籤:
