javiercbk / json_to_dart

Library that generates dart classes from json strings
https://javiercbk.github.io/json_to_dart/
The Unlicense
1.33k stars 371 forks source link

'List' is deprecated and shouldn't be used. #60

Closed iqfareez closed 2 years ago

iqfareez commented 3 years ago

Warning message:

'List' is deprecated and shouldn't be used. Try replacing the use of the deprecated member with the replacement.

Generated code:

  LocationCoordinate.fromJson(Map<String, dynamic> json) {
    states = json['states'].cast<String>();
    if (json['results'] != null) {
      results = new List<Results>();
      json['results'].forEach((v) {
        results.add(new Results.fromJson(v));
      });
    }
  }
javiercbk commented 3 years ago

Hey, thanks for reporting.

I believe the best replacement would be:

// results = new List<Results>();
results = new List<Results>.empty(growable: true);
iqfareez commented 3 years ago

Thank you. Your solution works

RaulUrtecho commented 3 years ago

Hey, thanks for reporting.

I believe the best replacement would be:

// results = new List<Results>();
results = new List<Results>.empty(growable: true);

How about to use a literal list notation?

// results = new List<Results>();
results = [];

Also from the efective dart guide:

DON’T use new. Linter rule: unnecessary_new

Dart 2 makes the new keyword optional. Even in Dart 1, its meaning was never clear because factory constructors mean a new invocation may still not actually return a new object.

The language still permits new in order to make migration less painful, but consider it deprecated and remove it from your code.

javiercbk commented 3 years ago

This project is all about honoring Dart's recommendations, and it seems that @RaulUrtecho is right.

I'll replace this with a non NEW solution shortly

javiercbk commented 2 years ago

It's done....sorry for taking soo long...It was a good nap though