I just started using flutter for web. Currently I'm trying to display data from realtime database. and this is the code that fetch the data and display it.
class Company extends StatelessWidget {
@override
Widget build(BuildContext context) {
DatabaseReference refe = database().ref('Company');
return Scaffold(
appBar: AppBar(),
body: StreamBuilder(
stream: database().ref('Company').onValue,
builder: (context, snap) {
if (snap.hasData) {
List key1 = [];
List item1 = [];
int len;
refe.once("value").then(
(data) {
len = data.snapshot.numChildren();
var a = data.snapshot.toJson();
a.forEach(
(key, values) {
key1.add(key);
item1.add(values);
},
);
},
);
return ListView.builder(
itemCount: len,
itemBuilder: (context, index) {
return Row(
children: [
Expanded(
child: Card(child: Text(item1[index]['compName'])),
),
Expanded(
child: Card(child: Text(item1[index]['companyID'])),
),
//Text('Company Name'),
],
);
},
);
} else
return CircularProgressIndicator();
},
),
);
}
}
The code itself runs fine but i got an error just below the results i display.
Displayed the data but have flutter error below it
The following IndexError was thrown building: RangeError (index): Index out of range: index should be less than 25: 25
Does anyone know the reason for the error?