首页 > 解决方案 > 将具有本地数据的函数转换为具有数据库数据的函数

问题描述

我有这个函数使用来自本地 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')

为了达到与我相同的结果,我必须在下一行中进行哪些更改?

标签: flutterdartgoogle-cloud-firestoreflutter-dependencies

解决方案


推荐阅读