flutter - 将具有本地数据的函数转换为具有数据库数据的函数
问题描述
我有这个函数使用来自本地 json 的数据:
Future loadCountries() async {
final data = await rootBundle.loadString('assets/country_codes.json');
final countriesJson = json.decode(data);
return countriesJson.keys.map<MyUser>((code) {
final json = countriesJson[code];
final newJson = json..addAll({'code': code.toLowerCase()});
return MyUser.fromJson(newJson);
}).toList()
..sort(Utils.ascendingSort);
}
现在我希望从 firebase 上的查询中提取我的数据,因此我的函数的新第一行将是:
final data = await countriesRef.doc(id).collection('countries')
为了达到与我相同的结果,我必须在下一行中进行哪些更改?
解决方案
推荐阅读
- c# - 如何调试 Xamarin watchOS 链接器错误
- handlebars.js - Handlebars 如何正确处理“..”(上一级)?
- python - 从 python STOMP 创建临时队列
- java - 完成“mvn clean install”后,有没有人注意到奇怪的数字?
- mongodb - MongoDB - 计算整个集合中数组元素的平均值
- apache-spark - 一个 livy 会话在头节点内存中维护多长时间?
- asp.net-core - Kestrel 在提供流量时抛出“Invalid Host header”错误
- excel - 4个条件4个答案的Excel语句
- javascript - 如何将mysql的数据行转换为javascript数组?Node.js 应用程序
- javascript - 将 CSS 和 JS 定位到特定表