I was following a tutorial of sorts and got to a section where we print out what we have in the firestore database. However for some reason my Provider.of seems to be returning null when there is at least one data entry. home.dart and MemoryList:
class Home extends StatelessWidget {
final AuthService _auth = AuthService();
@override
Widget build(BuildContext context) {
return StreamProvider<List<Person>>.value (
value: DatabaseService().memories,
initialData:[],
child: Scaffold(
backgroundColor: Colors.lightBlueAccent[50],
appBar: AppBar(
title: Text('Memory Bank'),
backgroundColor: Colors.deepPurple[300],
elevation: 0.0,
actions: <Widget>[
TextButton.icon(
icon: Icon(Icons.person),
label: Text('logout'),
onPressed: ()async{
await _auth.signOut();
},
),//textbutton
],//widget[]
),//appbar
body: MemoryList(),
)//scaffold
);//streamProvider.value
}
}
class MemoryList extends StatefulWidget {
@override
_MemoryListState createState() => _MemoryListState();
}
class _MemoryListState extends State<MemoryList> {
@override
Widget build(BuildContext context) {
final memories = Provider.of<List<Person>>(context);
print("current data:");
print(memories);
if(memories != null){
memories.forEach((element) {
print(element.name);
//print(element.name.events);
//print(element.name.likes);
});
}
return ListView.builder(
itemCount: memories.length,
itemBuilder: (context,index){
return MemoryTile(person: memories[index]);
}
);
}
}
For here the Provider.of<List>(context) returns with nothing.
The stream is:
final CollectionReference memoryCollection = FirebaseFirestore.instance.collection('memories');
Stream<List<Person>> get memories {
Stream<QuerySnapshot> snapshot_stream = memoryCollection.snapshots();
print("getting memories: ");
//print(snapshot_stream.first);
//print(snapshot_stream.first.toString());
return memoryCollection.snapshots().map(_memoryListFromSnapshot);
}
With a simple Person model with just a name:
class Person{
final String name;
Person({required this.name});
}
Any help would be appreciated!