Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

android - Flutter: Exception caught by Streambuilder

Hey I am trying to get data of my firestore database to display it in a chart. There are some similar Questions on this topic but they couldnt solve my problem. Following the error causing widget:

Widget _buildBody(context) {
    return StreamBuilder<QuerySnapshot>(
      stream: FirebaseFirestore.instance.collection('TopTen').snapshots(),
      builder: (context, snapshot) {
        if (!snapshot.hasData) {          
          return LinearProgressIndicator();
        } else {
          List<Klicks> klicks = snapshot.data.docs
              .map(
                  (documentSnapshot) => Klicks.fromMap(documentSnapshot.data()))
              .toList();
          return _buildChart(context, klicks);
        }
      }
    );
  }

After running my App the LinearProcessIndicator is shown quickly and then the errorpage gets displayed with the following message:

Failed assertion: boolean expression must not be null
The relevant error-causing widget was
StreamBuilder<QuerySnapshot>

If I dont quit the App the errormessage gets build all the time.

I've set up the firestore collection called 'TopTen'. As requested this is the 'Klicks' class

class Klicks{
  final int gesamtKlicks;
  final String name;

Klicks(this.gesamtKlicks,this.name);

 Klicks.fromMap(Map<String,dynamic> map)
 :assert(map['gesamtKlicks']=!null),
 assert(map['name']=!null),
gesamtKlicks=map['gesamtKlicks'],
name=map['name'];

@override
String toString() => "Record <$gesamtKlicks:$name>";
}

And finally the database:

this is how the database looks like

thanks in advance!


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

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...