简体   繁体   中英

rangeerror (index): invalid value: valid value range is empty: 0 in flutter while getting data from firebase

body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            StreamBuilder(
              stream: Firestore.instance.collection('scores').snapshots(),
              builder: (context, snapshot)
              {
                if(snapshot.hasData) return Text('Loading Data...');
                return Column(
                  children: <Widget>[
                    Text(snapshot.data.documents[0]['TeamOne']),
                    Text(snapshot.data.documents[0]['TeamTwo']),
                    Text(snapshot.data.documents[0]['toWin'].toString()),
                    Text(snapshot.data.documents[0]['runs'].toString()),
                    Text(snapshot.data.documents[0]['wickets'].toString()),
                    Text(snapshot.data.documents[0]['overs'].toString()),
                  ],
                );
              },

            )
          ],
        ),
      ),

I'm trying to get data from firebase but getting this error. first it goes to the first return statement and after some time it shows the red screen with error "rangeerror (index): invalid value: valid value range is empty: 0"

I think you can use ".".

if(!snapshot.hasData) return Text('Loading Data...');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM