New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implicit_this_reference_in_initializer false positive ? #35878

jaumard opened this Issue Feb 7, 2019 · 1 comment


None yet
2 participants
Copy link

jaumard commented Feb 7, 2019

I have the following case:

class Whatever  {
  final _analytics = KiWiAnalytics();
  final _observer = Lazy<FirebaseAnalyticsObserver>(() {

And I'm getting this error: error: Only static members can be accessed in initializers. (implicit_this_reference_in_initializer)
For me it should be an error as I'm not in an initializer anymore, but under a callback.

Dart VM version: 2.1.1-dev.0.1.flutter-ec86471ccc (Thu Jan 3 22:43:43 2019 +0000) on "macos_x64"


This comment has been minimized.

Copy link

vsmenon commented Feb 11, 2019

This is working as intended. The right hand side of an initializer cannot refer implicitly to this. E.g., in your example, there is no guarantee that the callback is not executed before _analytics is initialized.

Something like this (moving the initialization to a constructor with order explicit) should work:

class Whatever  {
  final _analytics; 
  final _observer; 

  Whatever() : this._(KiWiAnalytics());
  Whatever._(this._analytics) : _observer =;

@vsmenon vsmenon closed this Feb 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment