List 在 dart 中初始化之前无法访问对象
List can't access an object before it is initialized in dart
我创建了一个房屋对象以在名为 'favHouses' 的列表中添加成员。但是飞镖不允许我在构造函数中初始化之前添加这些成员。这是我的代码和我得到的错误。
List<House> favHouses = [houseAlanya];
House houseAlanya = new House(..);
我得到的错误:
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)
在 Dart 2.12 中,您可以使用 late
关键字进行延迟初始化。
late List<House> favHouses = [houseAlanya];
我创建了一个房屋对象以在名为 'favHouses' 的列表中添加成员。但是飞镖不允许我在构造函数中初始化之前添加这些成员。这是我的代码和我得到的错误。
List<House> favHouses = [houseAlanya];
House houseAlanya = new House(..);
我得到的错误:
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)
在 Dart 2.12 中,您可以使用 late
关键字进行延迟初始化。
late List<House> favHouses = [houseAlanya];