flutterdartblocstate-managementfreezed

"Missing concrete implementation of 'getter _$CounterState.count'. Try implementing the missing method, or make the class " flutter bloc with frrzzed


I got an error in using flutter bloc and freezed page using for state management I couldn't find solution

"Missing concrete implementation of 'getter _$CounterState.count'.
Try implementing the missing method, or make the class abstract"

Error Error Image


Solution

  • If you are using freezed version 3.0.0 or above you have to add abstract or sealed modifier as in the migration guide it is stated that

    Classes using the factory constructor now require a keyword sealed / abstract.

    check V3 Migration Guide

    add abstract/sealed modifier and run the build_runner command error will be gone. Try this

    @freezed
    abstract class CounterState with _$CounterState {
      const factory CounterState({required int count}) = _CounterState;
    
      factory CounterState.initial() => const CounterState(count: 0);
    }
    

    and then run this command

    dart run build_runner build