
# Beside ChangeNotifier

Signals stand beside `ChangeNotifier`, not instead of it. `@ChangeNotifierComponent` and `@NotifyListeners` of the Flutter starter stay as they are. Signals are a second way, for a bean whose fields change apart from each other.

## Why

A state bean of the Flutter starter notifies after every method: one notification for the whole bean. That is right for a bean that is one thing, such as a counter or a selection. A bean with several fields that change apart from each other (a basket's items, its coupon, a catalog's genre and its books) rebuilds every listener for every change. Signals tell by field.

## Example

The same basket, both ways:

```dart
// One notification for the bean, after every method.
@ChangeNotifierComponent()
class Basket {
  final _items = <Book>[];

  int get count => _items.length;

  void add(Book book) => _items.add(book);
}
```

```dart
// By field: a reader of `coupon` is not told when `items` changes.
@Component()
class Basket {
  @Signal()
  List<Book> items = [];

  @Signal()
  String? coupon;

  void add(Book book) => items.add(book);
}
```

## Which for what

| | State beans | Signals | Bloc |
|---|---|---|---|
| Package | `spring_boot_starter_flutter` | `spring_boot_starter_flutter_signals` | `flutter_bloc`, the app's own dependency |
| On the bean | `@ChangeNotifierComponent`, or `@NotifyListeners` on a `ChangeNotifier` | `@Signal`, `@Computed`, `@Effect` on members of a component | The bloc is a component |
| What is told | The bean's listeners, after a method | The readers of a field, when it is assigned | The listeners of the bloc's stream, for a new state |
| A Spring widget is built again | When its `build` read the bean | For the fields its `build` read | Not by itself: `BlocBuilder` is used |
| Values made from others | Getters, computed on every read | `@Computed`, kept until what it read changes | States the bloc emits |
| A `Future` or a `Stream` with its state | Written by hand | `@Computed`, with `state`, `refresh()`, `reload()` | Written as states |

The three live in one app: each is a bean, injected and scoped the same way.

- [State beans](../spring-boot-starter-flutter/state-beans.md): `@ChangeNotifierComponent` and `@NotifyListeners`.
- [Bloc and Cubit](../../docs/bloc.md): the third way, with no starter of its own.

## See also

- [State beans](../spring-boot-starter-flutter/state-beans.md)
- [Bloc and Cubit](../../docs/bloc.md)
- [Fields and computed values](fields-and-computed.md)
- [In widgets](widgets.md)
