2

I created a house object to have member in a list called 'favHouses'. But dart doesn't let me to add those members before i initialize in constructor. Here is my code and the error that i get.

List<House> favHouses = [houseAlanya];
House houseAlanya = new House(..); 

the error i get:

The instance member 'houseAlanya' can't be accessed in an initializer. Try replacing the reference to the instance member with a different expression dart(implicit_this_reference_in_initializer)

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
bach
  • 33
  • 4

1 Answers1

1

With Dart 2.12, you can use the late keyword for lazy initialization.

late List<House> favHouses = [houseAlanya];
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440