Flutter Dart - the argument type 'String' can't be assigned to the parameter type 'Map<String,dynamic>'

AgentRed

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));

err

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;
}
Akif

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.

edited at
0

Comments

0 comments
Login to comment

Related

The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'Map<String, dynamic>'. error showing in flutter

Flutter: The argument type 'dynamic' can't be assigned to the parameter type 'Map<String, dynamic>'

Flutter: The argument type 'HomePage Function(BuildContext, Map<String, dynamic>)' can't be assigned to the parameter type

Flutter Convert FromMap to list The argument type 'Object?' can't be assigned to the parameter type 'Map<String, dynamic>'

Dart - The argument type 'String' can't be assigned to the parameter type 'String'

Flutter-Firestore "The argument type 'Map<String, dynamic> Function()' can't be assigned to the parameter type 'Map<String, dynamic>"

Flutter : Facing an error like - The argument type 'Map<String, dynamic>?' can't be assigned to the parameter type 'Map<String, Object?>'

The argument type 'Map<String, dynamic> Function()' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'Iterable<Map<String, dynamic>>' can't be assigned to the parameter type 'List<Map<String, dynamic>>'

The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'Map<String, dynamic>'

Dart, flutter - The argument type 'String' can't be assigned to the parameter type 'Color?'

The argument type 'List<String>' can't be assigned to the parameter type 'String'.dart(argument_type_not_assignable) on the Dart

The argument type 'String' can't be assigned to the parameter type 'Uri'. Flutter

The argument type 'Set<String>' can't be assigned to the parameter type 'Map<String, dynamic>'

error using riverpod to The argument type 'String' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'dynamic' can't be assigned to the parameter type 'Map<String, dynamic>' from Lint vs Pedantic

The argument type 'dynamic' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'Future<dynamic>' can't be assigned to the parameter type 'String'

The argument type 'MaterialPageRoute<dynamic>' can't be assigned to the parameter type 'String'

The argument type 'Object' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'CollectionReference<Object?>' can't be assigned to the parameter type 'Query<Map<String, dynamic>>'. (Documentation)

JSON Serialization Issue: The argument type 'Tracks' can't be assigned to the parameter type 'Map<String, dynamic>'

error: The argument type 'Null' can't be assigned to the parameter type 'Map<String, dynamic>'

The argument type 'Stream<DocumentSnapshot<Map<String, dynamic>>>' can't be assigned to the parameter type 'Stream<DocumentSnapshot<TaskItems>>?'

The argument type 'Map<dynamic, dynamic>' can't be assigned to the parameter type 'Map<String, dynamic>' after updating the version of the SDK

Dart: The argument type 'String' can't be assigned to the parameter type 'FutureOr<String>

The argument type 'Map<String, Object>' can't be assigned to the parameter type 'String'.dartargument_type_not_assignable

flutter The argument type 'void Function(String)' can't be assigned to the parameter type 'void Function(String?)?' in flutter

The argument type 'void Function(String?)?' can't be assigned to the parameter type 'String? Function(String?)? in Flutter