NoSuchMethodError: Class 'List<Object?>' 没有实例 getter 'keys'

时间:2021-07-24 13:16:18

标签: firebase flutter firebase-realtime-database

event.snapshot.value.keys 无法读取此代码。 我在其他项目中使用了相同的代码。 并且工作得很好。现在不工作了。

我尝试了各种不同的方法。 但它从未奏效。

有人遇到过这样的问题吗?

这是我的模型;

class Country {
late String countryID;
late String countryName;
late bool enabled;

Country({
required this.countryID,
required this.countryName,
required this.enabled,
});

Country.fromJson(Map<String, dynamic> json) {
countryID = json['country_id'] ?? "";
countryName = json['country_name'] ?? "";
enabled = json['enabled'] ?? false;
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['country_id'] = this.countryID;
data['country_name'] = this.countryName;
data['enabled'] = this.enabled;
return data;
}
}


--i got this error

E/flutter (21425): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] 
Unhandled Exception: NoSuchMethodError: Class 'List<Object?>' has no 
instance getter 'keys'.
E/flutter (21425): Receiver: Instance(length:50) of '_GrowableList'
E/flutter (21425): Tried calling: keys
E/flutter (21425): #0      Object.noSuchMethod (dart:core- 
patch/object_patch.dart:63:5)
E/flutter (21425): #1      CountryController.subCountryStream.<anonymous 
closure>
package:srv_home_01/…/AuthControllers/country_controller.dart:54
E/flutter (21425): #2      _MapStream._handleData (dart:async/stream_pipe.dart:213:31)

0 个答案:

没有答案