Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

flutter - Why there is still error on List view length

I specified a StreamBuilder which have Gridview.builder as a function under builder of (StreamBuilder) and i specified the stream to Cloud Firestore. I specified the length of GridView.

The list worked and came out but it will be length was called to null error for about 2 seconds. The list will still show according to the length of the snapshot but it's still bringing the error.

Please what can I do?

question from:https://stackoverflow.com/questions/65851885/why-there-is-still-error-on-list-view-length

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are getting the error because data has not available at the time your build method runs. so, you need to check if data is available then show your Gridview.

See the following code in the builder method you need to check snapshot has data or not also check the connection status ones connection status is done you can show Gridview

builder:(BuildContext context, AsyncSnapshot<dynamic> snapshot) {
   if (!snapshot.hasData) {
     return Loader();
   }
   if (snapshot.connectionState == ConnectionState.done) {
      // Your Gridview should be here
   }

  return Loader();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...