我做了一个图表,数据取自API。但是我有一个问题,变量startDate和truck不能赋值,因为类型不同。有人知道是什么原因吗?
在此附上错误。
变量开始日期错误
可变转向架误差
下面是变量的JSON模型
class GraphicLoad {
GraphicLoad(
this.startDate,
this.excavator,
this.truck,
);
factory GraphicLoad.fromJson(Map<String, dynamic> json) =>
_$GraphicLoadFromJson(json);
Map<String, dynamic> toJson() => _$GraphicLoadToJson(this);
@JsonKey(name: 'start_date')
final DateTime startDate;
final String excavator;
final String truck;
}
在建立JSON模型后,编写函数进行解析
GraphicLoad _$GraphicLoadFromJson(Map<String, dynamic> json) => GraphicLoad(
DateTime.parse(json['start_date'] as String),
json['excavator'] as String,
json['truck'] as String,
);
Map<String, dynamic> _$GraphicLoadToJson(GraphicLoad instance) =>
<String, dynamic>{
'start_date': instance.startDate.toIso8601String(),
'excavator': instance.excavator,
'truck': instance.truck,
};
这是海图的代码
SplineAreaSeries<GraphicLoad, String>(
gradient: LinearGradient(
colors: <Color>[
ColorName.brandSecondaryBlue
.withOpacity(0.3),
ColorName.brandPrimaryBlue,
],
stops: <double>[0.2, 0.7],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
dataSource: graphicLoad,
xValueMapper: (GraphicLoad data, _) =>
data.startDate, // error in here---------------
yValueMapper: (GraphicLoad data, _) =>
data.truck, // error in here---------------
name: 'Trucks',
markerSettings: const MarkerSettings(
isVisible: false,
color: ColorName.brandPrimaryBlue,
),
),
1条答案
按热度按时间szqfcxe21#
您在委托函数
xValueMapper
和yValueMapper
上返回了错误的类型数据。xValueMapper
需要返回String
的函数yValueMapper
需要返回int
的函数