This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final:
This warning means you're using a class in Flutter (or Dart more generally) that is annotated with @immutable, which implies that all of its instance fields should be final — meaning they must be assigned once and never change afterward.
Here’s a quick breakdown:
๐ Why it happens
When a class is marked @immutable (commonly for widgets like StatelessWidget), Dart expects that the class behaves as immutable — no field should change after the object is constructed.
If any field is not marked as final, then the object could be mutated later, which breaks immutability.
This issue occurs when all the class variables are not declared as final. You can either make them final or for ignoring this warning you can add the following comment above the class declaration:
✅ How to fix it
You can add the following comment above the class declaration:
//ignore: must_be_immutable
Comments
Post a Comment