-1

Hej!,

so I found that List() is deprecated. How can I initiate the List and run for the length of my _data.length and fill it with my json _data[I] now?

Greetings Noob TopTickTom

class WakeProvider {
  Client client = Client();

  fetchFeatures() async {
    final response = await client.get('$_root/.json');
    if (response.statusCode == 200) {
      final parsedJson = json.decode(response.body);
      List _data = parsedJson['employee'];
      List _result = List();
      for (int i = 0; i < _data.length; i++) {
        _result.add(EmployeeModel.fromJson(_data[i]));
      }
      return _result;
    } else {
      throw NullThrownError();
    }
  }
TopTickTom
  • 21
  • 2

1 Answers1

1

I fixed it with initialising the new way after reading the documentation... :-)

 List _result = [];

TopTickTom
  • 21
  • 2
  • Please note that `List _result = List();` will throw away any type information since you are just creating a `List` where Dart can no longer make any guarantees about what types you are inserting and getting out of the list. In your example, what you properly want is instead: `final _result = []`. – julemand101 May 24 '21 at 17:24