I have this class which accept docID by passing the value when calling the DatabaseService class.
However when i am trying to put this docID variable into my firebase query. It shows that my ${docID} is an instance member and cant be accessed in an initialier. Pleasae help me.
Data passed in like this
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => announcementDetail(announcementlist.id),
),
announcementDetail class accepet the passed value
class announcementDetail extends StatelessWidget {
final String docID;
announcementDetail(this.docID);
@override
Widget build(BuildContext context) {
return StreamProvider<List <Announcement>>.value(
value: DatabaseService(uid: ' ', docID: docID).announcementDetailList,
initialData: [],
child: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text('Home'),
backgroundColor: Theme.of(context).primaryColor,
elevation: 0.0,
centerTitle: true,
),
body: Container(
child: Announcement_Detail_List(),
),
),
);
}
}
DatabaseService class accepts the value passed from announcementDetail class
class DatabaseService {
final String? uid;
final String? docID;
final bool toggleDate = false;
DatabaseService({ required this.uid, required this.docID});
final Query<Map<String, dynamic>> getAnnouncementDetail = FirebaseFirestore.instance.collectionGroup('announcementlist').where('id', isEqualTo: '${docID}');
//announcementdetail list from snapshot
List <Announcement> _announcementDetailListFromSnapshot(QuerySnapshot snapshot){
return snapshot.docs.map((doc){
return Announcement(
id: doc.id,
title: doc.get('title') ?? '',
dateTime: doc.get('dateTime') ?? '',
content: doc.get('content') ?? '',
aType: doc.get('announcementType') ?? '',
aLevel: doc.get('announcementLevel') ?? ''
);
}).toList();
}
// get announcementdetail stream
Stream<List <Announcement>> get announcementDetailList {
return getAnnouncementDetail.snapshots()
.map(_announcementDetailListFromSnapshot);
}
}
error part is here is DatabaseService Class
final Query<Map<String, dynamic>> getAnnouncementDetail = FirebaseFirestore.instance.collectionGroup('announcementlist').where('id', isEqualTo: '${docID}');