---
title: "Comment by Žan Fras on \"Dash Tips: Using Freezed with StateNotifier\" | Hashnode"
description: "How to add something like loading state? I tried: @freezed abstract class CounterState with _ $ CounterState { const factory CounterState.initial([ @Default ( 0"
url: "https://hashnode.com/posts/dash-tips-using-freezed-with-statenotifier/5e8fdd103801141f763ae8cf/comment/5ee7552b6c513725202ea149"
---

[Discussion](https://hashnode.com/posts/dash-tips-using-freezed-with-statenotifier/5e8fdd103801141f763ae8cf)

Comment [Dash Tips: Using Freezed with StateNotifier](https://hashnode.com/posts/dash-tips-using-freezed-with-statenotifier/5e8fdd103801141f763ae8cf)

[Žan Fras](https://hashnode.com/@frasza)

[Jun 15, 2020](https://hashnode.com/posts/dash-tips-using-freezed-with-statenotifier/5e8fdd103801141f763ae8cf/comment/5ee7552b6c513725202ea149)

How to add something like loading state?

I tried:

```
@freezed
abstract class CounterState with _$CounterState {
  const factory CounterState.initial([@Default(0) int value]) = _Initial;
  const factory CounterState.loading() = _Loading;
  const factory CounterState.current(int value) = _Current;
}
```

Of course I get an error if I try to use it in notifier, because current looses it:

```
The getter 'value' isn't defined for the type 'CounterState'.
```

How to go about it?

Thanks

[Žan Fras](https://hashnode.com/@frasza)

[Jun 15, 2020](https://hashnode.com/posts/dash-tips-using-freezed-with-statenotifier/5e8fdd103801141f763ae8cf/comment/5ee7552b6c513725202ea149#reply-5ee76a7f98c535462075e4e2)

What I did (to present loading state example) is:

```
@freezed
abstract class CounterState with _$CounterState {
  const factory CounterState.initial([@Default(0) int value]) = _Initial;
  const factory CounterState.loading(int value) = _Loading;
  const factory CounterState.current(int value) = _Current;
}
```

```
class CounterStateNotifier extends StateNotifier<CounterState>
    with LocatorMixin {
  CounterStateNotifier() : super(CounterState.initial());

  void increment() {
    state = CounterState.loading(state.value);
    Timer(
      Duration(seconds: 1),
      () => state = CounterState.current(state.value + 1),
    );
  }
}
```

```
StateNotifierBuilder(
              stateNotifier: context.watch<CounterStateNotifier>(),
              builder: (context, CounterState state, _) => state.when(
                initial: (value) => Text(
                  '$value',
                  style: Theme.of(context).textTheme.headline4,
                ),
                loading: (_) => CircularProgressIndicator(),
                current: (value) => Text(
                  '$value',
                  style: Theme.of(context).textTheme.headline4,
                ),
              ),
            )
```

But that is obviously 'hack'. Any tip? [Remi Rousselet](https://hashnode.com/@remi_rousselet) / [Ryan Edge](https://hashnode.com/@chimon)
