Error: The instance member … can’t be accessed in an initializer

Dart does not allow field initializers to refer to the object itself. Fields must always be fully initialized before any access is given to the object begin created.
The initializers can only access static and top-level variables, not any instance variables on the object itself.

With null safety, you will be allowed to write late String jsonText = this.something + this.other;. That field will then not be initialized until it’s first read or written, which is necessarily after the object itself has been created.

Leave a Comment