0

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
  • 175,842
  • 51
  • 533
  • 380
bach
  • 13
  • 3

1 Answers1

0

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

late List<House> favHouses = [houseAlanya];
CopsOnRoad
  • 175,842
  • 51
  • 533
  • 380