[英]I need help making a compound query from Dart-Flutter to FireBase
Hello, I need help to make a query ordered by date and grouped by type, to obtain an array for each type according to the selected date range. i am working using dart-flutter and firebase.
I am currently generating by date range我目前正在按日期范围生成
Future<List<JobsData>> getEntry({ DateTime from, DateTime to}) async {
try {
//print(from?.toIso8601String());
QuerySnapshot<Map<String, dynamic>> _snap = await _firestore
.collection("applications")
//.where("statusLabel", isEqualTo: "Avalaible")
.where("dateOfApplication",
isGreaterThanOrEqualTo: from?.toIso8601String())
.where("dateOfApplication",
isLessThanOrEqualTo: to?.toIso8601String())
//.where("statusLabel", isEqualTo: "Finalized")
.orderBy("dateOfApplication")
//.groupBy("userApliedId")
.get();
return _snap.docs.map((e) => JobsData.fromJson(e.data())).toList() ;
} on FirebaseException catch (e) {
throw e;
}
}
I tried different ways but I did not get results, I am sorry if there are errors but I am a beginner.我尝试了不同的方法,但没有得到结果,如果有错误,我很抱歉,但我是初学者。
for (var i=0; i < jobsData.length; i++) {
var sorted = jobsData;
sorted.sort((a, b) => a.userApliedId.compareTo(b.userApliedId)
);
if (sorted[i].userApliedId == sorted[i].userApliedId && sorted[i].statusLabel == 'Finalized'){
print(sorted[i].idJob);
print(sorted[i].jober);
print(sorted[i].customer);
print(sorted[i].date);
print(sorted[i].statusLabel);
print(sorted[i].imageUrl);
final datas = sorted
.map((i) => [
i.imageUrl,
i.userApliedId,
// e.id,
i.date,
i.Actividad,
i.customer,
i.pago,
i.statusLabel,
i.jober,
i.imageUrl.toString().split(" ").first,
// e.stages.toList(),
])
.toList();
print(datas);
}
I need to fix the data so that it appears in my pdf generation like this.我需要修复数据,以便它像这样出现在我的 pdf 代中。
Filtered by dates and this is data of a single type按日期过滤,这是单一类型的数据
Do not use .toIso8601String()
, Firestore offers a data type called Timestamp
, you can use Timestamp.fromDate(to)
and you can get a Timestamp
object that you can compare with.不要使用
.toIso8601String()
,Firestore 提供了一种名为Timestamp
的数据类型,您可以使用Timestamp.fromDate(to)
并且可以获得可以与之比较的Timestamp
object。 Make sure to have the same data type in your database (Do not save the date as String
there is a choice called Timestamp
) see timestamp on firestore .确保数据库中的数据类型相同(不要将日期保存为
String
,有一个名为Timestamp
的选项)请参阅 firestore 上的时间戳。
.where("dateOfApplication",
isGreaterThanOrEqualTo: Timestamp.fromDate(from!))
.where("dateOfApplication",
isLessThanOrEqualTo:Timestamp.fromDate(to!))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.