Skip to content

Dart method names fromMap() and toMap() should not apply to functions that handle Strings #1719

Description

@pohara60

Here is some example dart code generated with the option to use Map in the method names:

List<Sensordata> sensordataFromMap(String str) => List<Sensordata>.from(json.decode(str).map((x) => Sensordata.fromMap(x)));

String sensordataToMap(List<Sensordata> data) => json.encode(List<dynamic>.from(data.map((x) => x.toMap())));

class Sensordata {
    Sensordata({
        this.sensor,
        this.data,
    });

    final String sensor;
    final List<Datum> data;

    factory Sensordata.fromMap(Map<String, dynamic> json) => Sensordata(
        sensor: json["sensor"],
        data: List<Datum>.from(json["data"].map((x) => Datum.fromMap(x))),
    );

    Map<String, dynamic> toMap() => {
        "sensor": sensor,
        "data": List<dynamic>.from(data.map((x) => x.toMap())),
    };
}

The first two functions sensordataFromMap and sensordataToMap process a JSON String, not a Map, and should be named as they are without the option, i.e. sensordataFromJson and sensordataToJson.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions