---
title: "Discussion on \"Dash Tips: Using Freezed with StateNotifier\" | Hashnode"
description: "Discussion on \"Dash Tips: Using Freezed with StateNotifier\". Justification\nPreviously I wrote about using freezed with the awesome bloc library.  Now let's look at the same example implemented with state_notifier to get a good understanding of the differences.\nThe Counter State Notifier\nimport 'package:freezed..."
url: "https://hashnode.com/posts/dash-tips-using-freezed-with-statenotifier/5e8fdd103801141f763ae8cf"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Dash Tips: Using Freezed with StateNotifier](https://poetryincode.dev/dash-tips-using-freezed-with-statenotifier?utm_source=hashnode&utm_medium=feed)

Justification Previously I wrote about using freezed with the awesome bloc library. Now let's look at the same example implemented with state\_notifier to get a good understanding of the differences. The Counter State Notifier import 'package:freezed...

Apr 10, 2020 · 6 min read · poetryincode.dev  
Updated Nov 2, 2020  
Read the article

-   [#flutter](https://hashnode.com/tag/flutter)
-   [#flutter-cjx3aa7op001jims1kuwl3ekz](https://hashnode.com/tag/flutter-cjx3aa7op001jims1kuwl3ekz)

## Written by

[Ryan Edge](https://hashnode.com/@chimon)

@chimon · Charlotte, NC

  
[View profile](https://hashnode.com/@chimon)

Flutter & full-stack JavaScript enthusiast

I am a developer who is passionate about building applications and an enthusiast of all things JavaScript, Dart, and Flutter

## Responses 2

Markdown supported · ⌘↵ to post

[Ž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)

[Remi Rousselet](https://hashnode.com/@remi_rousselet)

[Apr 13, 2020](https://hashnode.com/posts/dash-tips-using-freezed-with-statenotifier/5e8fdd103801141f763ae8cf/comment/5e94a72a28f1a84f59c4a472)

Features like middlewares are still doable here though:

The setter of "state" is overridable.

[Ryan Edge](https://hashnode.com/@chimon)

[Apr 13, 2020](https://hashnode.com/posts/dash-tips-using-freezed-with-statenotifier/5e8fdd103801141f763ae8cf/comment/5e94a72a28f1a84f59c4a472#reply-5e94a7e94e2f534a59f358b2)

Most definitely! StateNotifier can be scaled up to match Bloc capabilities. That point is more to highlight reasons Bloc may be overkill.
