FireStore 错误的 Map<String, dynamic>
Map<String, dynamic> for FireStore Errors
正在尝试为来自 FireStore 的项目创建映射:
class Hero {
final int id;
String name;
bool pickupNeeded;
String url;
bool partPickup;
Hero(this.id, this.name, this.pickupNeeded, this.url, this.partPickup);
factory Hero.fromJson(Map<String, dynamic> hero) =>
Hero(_toInt(hero['id']), hero['name'], hero['pickupNeeded'], hero['url'], hero['partPickup']);
Map toJson() => {'id' : id, 'name': name, 'pickupNeeded' : pickupNeeded, 'url' : url, 'partPickup' : partPickup,};
int _toInt(id) => id is int ? id : int.parse(id);
然而,_toInt in the hero(_toInt(hero['id']
...给出错误:"Instance members can't be accessed from a factory constructor"
我错过了什么? AngularDart 英雄之旅在他们的 GitHub sample
上是这样的。
hero_service 获得英雄召唤:
Future<Hero> get(dynamic id) async {
try {
return Hero.fromJson(id);
} catch (e) {
throw _handleError(e);
}
}
调用它的 Hero 组件:
void onActivate(_, RouterState current) async {
final id = RoutePaths().getId(current.parameters);
if (id != null) hero = await (_heroService.get(id));
}
让 _toInt
静态,你就是金色的。
static int _toInt(id) => id is int ? id : int.parse(id);
正在尝试为来自 FireStore 的项目创建映射:
class Hero {
final int id;
String name;
bool pickupNeeded;
String url;
bool partPickup;
Hero(this.id, this.name, this.pickupNeeded, this.url, this.partPickup);
factory Hero.fromJson(Map<String, dynamic> hero) =>
Hero(_toInt(hero['id']), hero['name'], hero['pickupNeeded'], hero['url'], hero['partPickup']);
Map toJson() => {'id' : id, 'name': name, 'pickupNeeded' : pickupNeeded, 'url' : url, 'partPickup' : partPickup,};
int _toInt(id) => id is int ? id : int.parse(id);
然而,_toInt in the hero(_toInt(hero['id']
...给出错误:"Instance members can't be accessed from a factory constructor"
我错过了什么? AngularDart 英雄之旅在他们的 GitHub sample
上是这样的。
hero_service 获得英雄召唤:
Future<Hero> get(dynamic id) async {
try {
return Hero.fromJson(id);
} catch (e) {
throw _handleError(e);
}
}
调用它的 Hero 组件:
void onActivate(_, RouterState current) async {
final id = RoutePaths().getId(current.parameters);
if (id != null) hero = await (_heroService.get(id));
}
让 _toInt
静态,你就是金色的。
static int _toInt(id) => id is int ? id : int.parse(id);