I need to pass 2 arguments in ChartSampleData()
but I'm having trouble because it says that
List<ChartSampleData> _list = [];
_list.add(ChartSampleData.fromMap(
'${formattedDate.toString()}', redeemedToday[index].total));
the argument type 'String' can't be assigned to the parameter type 'Map<String,dynamic>'
here's my class
i tried doing these,
Code:
class ChartSampleData {
ChartSampleData(this.xValue, this.yValue);
ChartSampleData.fromMap(
Map<String, dynamic> dataMap0, Map<String, dynamic> dataMap1)
: xValue = dataMap0['x'],
yValue = dataMap1['y'];
final dynamic xValue;
final dynamic yValue;
}
I think you need to change your model class like this:
class ChartSampleData {
String xValue;
String yValue;
ChartSampleData({this.xValue, this.yValue});
ChartSampleData.fromJson(Map<String, dynamic> json) {
xValue = json['xValue'];
yValue = json['yValue'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['xValue'] = this.xValue;
data['yValue'] = this.yValue;
return data;
}
}
You can use this website to convert your JSON to a Dart Model.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments