Dart不允许字段初始化器引用对象本身。在开始创建对象之前,字段必须被完全初始化。初始化器只能访问静态变量和顶层变量,不能访问对象本身的任何实例变量。
class Test { String initial = "this thing"; String other = initial;//This leads to the same error that you have }
解决: 将初始化赋值方法放置在构造函数或者initState中
Dart不允许字段初始化器引用对象本身。在开始创建对象之前,字段必须被完全初始化。初始化器只能访问静态变量和顶层变量,不能访问对象本身的任何实例变量。
class Test { String initial = "this thing"; String other = initial;//This leads to the same error that you have }
解决: 将初始化赋值方法放置在构造函数或者initState中