Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Dart error: a field or getter can't be used while the object is still being built

ErrorThe instance member 'params' can't be accessed in an initializer.

Short answer

An initializer list and a plain field initializer run before the object exists, so they cannot read this or any instance member. Pick one: make the member static, use a value that does not depend on the instance, or mark the field late so it initializes on first use.

  • Applies to Dart 3.x, Flutter 3.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the line the analyzer points at and ask what the initializer is reading: a getter, a method, a constructor parameter, or another field.

    dart analyze
  2. 2Match what you see, then jump to its fix

    1. 1The error is on a line like C() : x = defaultX;A constructor initializer list uses an instance getter or fieldFix
    2. 2The error is on a field declaration such as final b = a + 1;A field initializer needs another instance fieldFix

What does the error look like?

  • The instance member 'params' can't be accessed in an initializer.

Cause 1 of 2

A constructor initializer list uses an instance getter or field

1Check

Look for a getter or method of the same class used on the right-hand side of a colon initializer.

class C {
  int x;
  C() : x = defaultX;   // reported
  int get defaultX => 0;
}

2Fix

Make the member static, or replace the reference with an expression that needs no instance.

class C {
  int x;
  C() : x = defaultX;
  static int get defaultX => 0;
}

3Verify

The analyzer no longer reports the line.

dart analyze

Confirmed by dart.dev

Did this fix it?

Cause 2 of 2

A field initializer needs another instance field

1Check

A field that is initialized from another field of the same object needs this, which does not exist yet.

class Dish {
  String name = 'Feijoada';
  String description = 'Try the $name today!';   // reported
}

2Fix

Declare the dependent field late. A late field with an initializer is initialized when it is first read, and that initializer may use this.

class Dish {
  String name = 'Feijoada';
  late String description = 'Try the $name today!';
}

3Verify

Analyze, then read the field once to confirm it holds the expected value.

dart analyze

Confirmed by dart.dev

Did this fix it?

How do I stop it coming back?

  • Compute values from other fields in the constructor body, in a factory, or in a late field, not in the initializer list.
  • Keep initializer lists for simple assignments from constructor parameters and constants.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.