So I try to build Sliverlist on the first run I am hard-coding the child count to 20 (e.g.) and the app works just fine but if I try to set the childCount to the length of my FireStore collection on the first run i get the error
======== Exception caught by widgets library =======================================================
The following NoSuchMethodError was thrown building:
The getter 'length' was called on null.
Receiver: null
Tried calling: length
BUT! if I first set the childCount manually to 20 and then doing hot reload to the app with the childCount set to handlyCalls.length it works like it should, any suggestions?
class HandlyCallsList extends StatefulWidget {
@override
_HandlyCallsListState createState() => _HandlyCallsListState();
}
class _HandlyCallsListState extends State<HandlyCallsList> {
@override
Widget build(BuildContext context) {
final handlyCalls = Provider.of<List<HandlyCall>>(context);
int count = 20;
return SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, index) {
print('!!!!!!!!!!!! 11111111111111111111 ${handlyCalls.length}');
return HandlyCallTile(handlyCall: handlyCalls[index]);
},
childCount: handlyCalls.length,
),
);
UPDATE
this is the handyCall to list function
List<HandlyCall> _handlyCallListFromSnapshot(QuerySnapshot snapshot) {
return snapshot.docs.map((document) {
return HandlyCall(
title: document.data()['title'] ?? '',
type: document.data()['type'] ?? '',
reward: document.data()['reward'] ?? null,
money: document.data()['money'] ?? 0,
name: document.data()['name'] ?? '',
rating: document.data()['rating'] ?? 25,
user: document.data()['user'] ?? null,
);
}).toList() ;
}
//get userProfile stream
Stream<List<HandlyCall>> get handlyCalls {
return handlyCallsCollection.snapshots().
map(_handlyCallListFromSnapshot);
}
>(context);
– Omar Fayad Mar 16 '21 at 15:16