首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何以有序的方式从防火墙数据库中检索数据。当我把它作为地图检索时,出了点问题

如何以有序的方式从防火墙数据库中检索数据。当我把它作为地图检索时,出了点问题
EN

Stack Overflow用户
提问于 2021-12-18 18:43:35
回答 1查看 109关注 0票数 0
代码语言:javascript
复制
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;

}

如何以有序化的方式从防火墙数据库中检索数据,因为数据是随机检索的。

我尝试了orderByKey(),但是它没有像被忽略的那样工作

另外,我尝试了SortedMap包(https://pub.dev/packages/sortedmap),但是它也没有工作

EN

回答 1

Stack Overflow用户

发布于 2021-12-18 19:18:59

这是为我工作(FirebaseFirestore)

代码语言:javascript
复制
CollectionReference _collectionRef =
      FirebaseFirestore.instance.collection('users');
    QuerySnapshot querySnapshot = await _collectionRef.orderBy("dateOfBirth").get();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70406104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档