flutter json_serializable generated code analysis error error: Missing parameter type for 'e'
flutter json_serializable generated code analysis error error: Missing parameter type for 'e'
如标题所述,生成的代码显示 'e' 错误。错误状态为 error: Missing parameter type for 'e'. 当然,如果可以修改生成的代码,我可以这样做。但是,这似乎是一个非常糟糕的先例。
生成的代码是:
RatingResponseModel(
propertyId: json['propertyId'] as String,
ownerId: json['ownerId'] as String,
renterId: json['renterId'] as String,
ratedDate: DateTime.parse(json['ratedDate'] as String),
ratings: (json['ratings'] as List<dynamic>)
.map((e) => RatedDimensionModel.fromJson(e as Map<String, dynamic>))
.toList(),
);
class 看起来像:
part 'rating_response_model.g.dart';
@JsonSerializable(explicitToJson: true)
class RatingResponseModel {
RatingResponseModel({
required this.propertyId,
required this.ownerId,
required this.renterId,
required this.ratedDate,
required this.ratings,
});
/// A necessary factory constructor for creating a new User instance
/// from a map. Pass the map to the generated `_$MyClassNameFromJson()`
/// constructor. The constructor is named after the source class.
factory RatingResponseModel.fromJson(Map<String, dynamic> json) =>
_$RatingResponseModelFromJson(json);
/// `toJson` is the convention for a class to declare support for
/// serialization to JSON. The implementation simply calls the private,
/// generated helper method `_$MyClassNameToJson`.
Map<String, dynamic> toJson() => _$RatingResponseModelToJson(this);
final String propertyId;
final String ownerId;
final String renterId;
final DateTime ratedDate;
final List<RatedDimensionModel> ratings;
}```
The app seems to work properly, as do the unit tests - including the to/from json unit tests. Showing a syntax error in generated code is annoying. It makes me wonder if I have done something wrong. Worse, will it fail unexpectedly?
I am using json serializable: ^6.1.4 and json annotation: ^4.4.0. Flutter is 2.8.1. The ide is Intellij IDEA 2021.3.1.
我改了:
.map((e) =>
收件人:
.map((dynamic e) =>
而且,正如@hiashutoshsingh 所说,这解决了分析错误的问题。此解决方案的缺点是,每次 运行 构建 运行ner 时,您都需要再次更改生成的代码。
如标题所述,生成的代码显示 'e' 错误。错误状态为 error: Missing parameter type for 'e'. 当然,如果可以修改生成的代码,我可以这样做。但是,这似乎是一个非常糟糕的先例。
生成的代码是:
RatingResponseModel(
propertyId: json['propertyId'] as String,
ownerId: json['ownerId'] as String,
renterId: json['renterId'] as String,
ratedDate: DateTime.parse(json['ratedDate'] as String),
ratings: (json['ratings'] as List<dynamic>)
.map((e) => RatedDimensionModel.fromJson(e as Map<String, dynamic>))
.toList(),
);
class 看起来像:
part 'rating_response_model.g.dart';
@JsonSerializable(explicitToJson: true)
class RatingResponseModel {
RatingResponseModel({
required this.propertyId,
required this.ownerId,
required this.renterId,
required this.ratedDate,
required this.ratings,
});
/// A necessary factory constructor for creating a new User instance
/// from a map. Pass the map to the generated `_$MyClassNameFromJson()`
/// constructor. The constructor is named after the source class.
factory RatingResponseModel.fromJson(Map<String, dynamic> json) =>
_$RatingResponseModelFromJson(json);
/// `toJson` is the convention for a class to declare support for
/// serialization to JSON. The implementation simply calls the private,
/// generated helper method `_$MyClassNameToJson`.
Map<String, dynamic> toJson() => _$RatingResponseModelToJson(this);
final String propertyId;
final String ownerId;
final String renterId;
final DateTime ratedDate;
final List<RatedDimensionModel> ratings;
}```
The app seems to work properly, as do the unit tests - including the to/from json unit tests. Showing a syntax error in generated code is annoying. It makes me wonder if I have done something wrong. Worse, will it fail unexpectedly?
I am using json serializable: ^6.1.4 and json annotation: ^4.4.0. Flutter is 2.8.1. The ide is Intellij IDEA 2021.3.1.
我改了:
.map((e) =>
收件人:
.map((dynamic e) =>
而且,正如@hiashutoshsingh 所说,这解决了分析错误的问题。此解决方案的缺点是,每次 运行 构建 运行ner 时,您都需要再次更改生成的代码。