やりたいこと
flutterとfirebaseを用いて今月のデータのクエリをしたいのですが、取得できませんでした。
ご教授お願いします。
dart
1 2 List<ShowData> personDataBirthdayList = []; 3 4 5 static DateTime todayDate = DateTime.now(); 6 Timestamp nowTimeDate = Timestamp.fromDate(DateTime(todayDate.month)); 7 Timestamp DateEnd = Timestamp.fromDate(DateTime.utc(todayDate.month + 1)); 8 9 //データの取得 10 Future getSecondPageBir() async { 11 final snapshot = await FirebaseFirestore.instance 12 .collection('users') 13 .doc(uid) 14 .collection('data') 15 .where('birthday') 16 .startAt([nowTimeDate]) 17 .endAt([DateEnd]) 18 .get(); 19 final docs = snapshot.docs; 20 final personDataBirthdayList = docs.map((doc) => ShowData(doc)).toList(); 21 this.personDataBirthdayList = personDataBirthdayList; 22 notifyListeners(); 23 } 24 25 //データの取得 リアルタイム 26 Future getSecondPageBirRealtime() async { 27 final snapshots = await FirebaseFirestore.instance 28 .collection('users') 29 .doc(uid) 30 .collection('data') 31 .where('birthday') 32 .startAt([nowTimeDate]) 33 .endAt([DateEnd]) 34 .snapshots(); 35 snapshots.listen((snapshot) { 36 final docs = snapshot.docs; 37 final personDataBirthdayList = docs.map((doc) => ShowData(doc)).toList(); 38 this.personDataBirthdayList = personDataBirthdayList; 39 notifyListeners(); 40 }); 41 } 42} 43
dart
1class ShowData{ 2 ShowData(DocumentSnapshot doc){ 3 this.name = doc['name']; 4 this.description = doc['description']; 5 this.sex = doc['sex']; 6 this.company = doc['company']; 7 this.age = doc['age']; 8 this.imgURL = doc['img']; 9 this.like = doc['like']; 10 this.documentID = doc.id; 11 this.timeNow = doc['timeNow']; 12 this.birday = doc['birday']; 13 } 14 15 String? documentID; 16 String? name; 17 String? description; 18 int? sex; 19 String? company; 20 int? age; 21 String? imgURL; 22 bool? like; 23 Timestamp? timeNow; 24 Timestamp? birday; 25 26} 27
あなたの回答
tips
プレビュー