I am using Null -Safety then I keep getting this error, anywhere I user snapshot in my code
here is the error
here is my code
StreamBuilder(
stream: firestore
.collection('interest')
.doc('${auth.currentUser?.uid}')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: snapshot.data!['Interest'].length ,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(top: 12.0),
child: bottomCardList(
'assets/1 (6).jpeg',
snapshot.data!['Interest'][index]
.toString(),
),
);
});
}),
Thanks
There are a few solutions:
Provide a type to your
StreamBuilder
:Provide a type to the second parameter of your
builder
:Use
as
to downcast theObject
toMap