Any state library

Use the state object your screen already has. Tandem needs its capabilities and a stream of changes.

surface gives Tandem the screen's state object. Its changes getter returns a broadcast stream with an event for every state change. No adapter package is required.

Statechanges
bloc's Cubitstream
ChangeNotifier or ValueNotifiera broadcast controller updated by notifyListeners
Riverpod's Notifiera broadcast controller updated by listenSelf in build

ChangeNotifier

A ChangeNotifier can report changes through a StreamController<Object?>.broadcast() and close the controller when the state object is disposed.

  final _changes = StreamController<Object?>.broadcast();
  // …
  @override
  Stream<Object?> get changes => _changes.stream;

  @override
  void notifyListeners() {
    super.notifyListeners();
    _changes.add(null);
  }

  @override
  void dispose() {
    unawaited(_changes.close());
    super.dispose();
  }

Use a broadcast controller because each new Tandem session subscribes to the stream again.

Riverpod

A Notifier can report changes through a broadcast controller. Register listenSelf((_, next) => _changes.add(next)) in build. Riverpod removes that listener before the next rebuild.

Do not close this controller in ref.onDispose, which also runs before provider rebuilds. The controller must remain available for the rebuilt provider and its next Tandem session.

Use ref.read(yourProvider.notifier) in surface: and keep the provider alive by watching it from a widget below the scope. This page's code example is a plain ChangeNotifier. The repository has no Riverpod example.

riverpod_generator and tandem_generator cannot generate code for the same class. Both generate a _$Name mixin, so write the Riverpod provider by hand.

Scope lifetime

Place TandemScope below the widget that owns the state object, such as its BlocProvider or ChangeNotifierProvider. The scope then disposes its session before the owner closes the state object.

For provider, surface: reads the object with context.read<ShoppingListNotifier>().