Here is my code that produces a Null check operator used on a null value - error for this line: snapshot.data!.docs.map((DocumentSnapshot document) {
return ListView(
children:
snapshot.data!.docs.map((DocumentSnapshot document) {
Map<String, dynamic> data =
document.data()! as Map<String, dynamic>;
My full StreamBuilder code in body :
body: StreamBuilder<QuerySnapshot?>(
stream: _usersStream,
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot?> snapshot) {
if(snapshot.data !=null) {
snapshot.data!.docs.map((DocumentSnapshot document) async {
if (snapshot.hasError) {
return Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
});
}
return ListView(
children:
snapshot.data!.docs.map((DocumentSnapshot document) {
Map<String, dynamic> data =
document.data()! as Map<String, dynamic>;
return InkWell(
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
// elevation: 0.0,
child: Container(
child: Column(
children: [
Container(
// margin: EdgeInsets.all(20.0),
width: double.infinity,
height: 260.0,
decoration: BoxDecoration(
color: Colors.blue,
image: DecorationImage(
image: NetworkImage(data['images'][0]),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15),
topRight: Radius.circular(15),),
)
),
ListTile(
title: Text(data['catName']),
// subtitle: Text(data['images']),
),
],
),
),
),
onTap: () {
//Go to the next screen with Navigator.push
print(data['id']);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PostBook(id: data['id'])));
},
);
}
).toList(),
);
},
),