I tried to run this code but it gives me the error provided in the title, also it says (The body might complete normally, causing 'null' to be returned, but the return type, 'Widget', is a potentially non-nullable type.), any help to solve this issue would be appreciated!
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection("chats").snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot){
if(snapshot.hasError) {
return Center (
child: Text("There is a problem"),
);
}
if(snapshot.connectionState == ConnectionState.waiting) {
return Center (
child: Text("Loading"),
);
}
if(snapshot.hasData) {
return CustomScrollView(
slivers: [
CupertinoSliverNavigationBar(
largeTitle: Text("Chats"),
),
SliverList(
delegate: (
SliverChildListDelegate(
snapshot.data!.docs.map((DocumentSnapshot document) {
Map<String, dynamic> data = document.data()!as Map<String, dynamic>;
return CupertinoListTile(title: Text(data['title']),
);
}).toList())))
],
);
}
});
}