如何在flutter中以排序的方式从firebase数据库中检索数据.当我将其作为Map检索时出现了问题


import 'dart:convert';
import 'package:firebase_database/firebase_database.dart';
import 'package:lowmium/const/const.dart';
import 'package:lowmium/model/popular_item_model.dart';
import 'package:sortedmap/sortedmap.dart';
Future<List<PopularItemModel>> getMostPopular() async {
var list = List<PopularItemModel>.empty(growable: true);
var source = await FirebaseDatabase.instance.ref().child('a').child('b').child(MOST_POPULAR_REF).orderByKey().once();
// Map<dynamic, dynamic> values = source.value;
Map<dynamic, dynamic> values = source.snapshot.value as Map; //firebase_database ver (9.0.4) <- the problem is here 
values.forEach((key, value) {
list.add(PopularItemModel.fromJson(jsonDecode(jsonEncode(value))));
});
return list;
}

如何在flutter中以排序的方式从firebase数据库中检索数据,因为数据是以随机方式检索的

我尝试了orderByKey((,但它不起作用[就像它被忽略了]

此外,我还试用了SortedMap软件包(https://pub.dev/packages/sortedmap)它也不起作用

这对我有效(FirebaseFirestore(

CollectionReference _collectionRef =
FirebaseFirestore.instance.collection('users');
QuerySnapshot querySnapshot = await _collectionRef.orderBy("dateOfBirth").get();

最新更新