-1

I'm trying to show a list of reminder where user see all their reminders and able to edit it. I'm using StreamProvider so that I'm able to access in child widget. I map the DocumentSnapShot into MedReminder object. The StreamProvider should return List of MedReminder object. But in the ReminderList widget the Provider return null.

Stream:

  List<MedReminder> _medReminderListFromSnapshot(QuerySnapshot snapshot) {
    print('here is db');
    return snapshot.documents.map((doc) {
      return MedReminder(
        remindId: doc.data['remindId'] ?? '',
        howManyTimeDay: doc.data['howManyTimeDay'] ?? '',
        frequency: doc.data['frequecy'] ?? '',
        hour: doc.data['hour'] ?? '',
        min: doc.data['min'] ?? '',
        dateStarted: doc.data['dateStarted'] ?? '',
        dateEnded: doc.data['dateEnded'] ?? '',
        dateRefill: doc.data['dateRefill'] ?? '',
        quantityTime: doc.data['quantityTime'] ?? '',
      );
    }).toList();
  }
  Stream<List<MedReminder>> get medReminders {
    return userCollection.document(uid).collection('medic_reminder').snapshots()
        .map(_medReminderListFromSnapshot);
  }

Reminder Page:

Widget build(BuildContext context) {
    final user = Provider.of<User>(context);
    return StreamProvider<List<MedReminder>>.value(
      value: DatabaseService(uid: user.uid).medReminders,
      child: Scaffold(
        body: Container(
          child: ReminderList(),
        ),
      ),
    );
  }

Reminder List widget(here the provider returning null):

Widget build(BuildContext context) {
    final reminders = Provider.of<List<MedReminder>>(context) ?? [];
    reminders.forEach((reminder) {
      print(reminder.remindId);
    });
    return ListView.builder(
          itemCount: reminders.length,
        itemBuilder: (context, index) {
      return ReminderTile();
    });
  }

Please help me thanks.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

-1
Stream<List<MedReminder>> get medReminders {
    return userCollection.snapshots()
        .map(_medReminderListFromSnapshot);
  }

Store Data In userCollection with uid, dont add other collections

like

collectionReference userCollection = Firestore.instance.collection('users');

when saving data in 'users'

userCollection.document(uid).setData()..

then it works