I have a cupertino picker on flutter that gets its children from firestore.
return CupertinoPicker(
itemExtent: 50,
onSelectedItemChanged: (int index) {
setState(() {
_selectedUserId = user[index].userId;
_selectedUserName = user[index].name;
IosUserDropdownList.selectedUserId = user[index].userId;
IosUserDropdownList.selectedUserName = user[index].name;
});
print(_selectedUserId);
print(_selectedUserName);
},
children: user.map((user) {
return CupertinoButton(
onPressed: () {},
child: Text(
user.name,
style: TextStyle(color: CupertinoColors.activeBlue),
),
);
}).toList(),
);
This is how I get the users from Firestore:
Stream<List<UserData>> get users {
return userCollection.snapshots().map(_userListFromSnapshot);
}
And convert it to List using my UserData model:
List<UserData> _userListFromSnapshot(QuerySnapshot snapshot) {
return snapshot.documents.map((doc) {
return UserData(
name: doc.data['name'] ?? '',
userId: doc.documentID ?? '');
}).toList();
}
The problem is that when I navigate to the page with the picker, I dont see any data on the picker. when I do a hot refresh however, the data shows up.
The picker also shows data when I am on the next page and do a Navigator.pop(context) back to the screen with the picker. I have been on this for weeks with no success. Please help.
Thanks.
> get users { return userCollection.snapshots().map(_userListFromSnapshot); }
– Sky Lurk Nov 04 '20 at 15:34