build method

Initialize a Notifier.

It is safe to use Ref.watch or Ref.listen inside this method.

If a dependency of this Notifier (when using Ref.watch) changes, then build will be re-executed. On the other hand, the Notifier will not be recreated. Its instance will be preserved between executions of build.

If this method throws, reading this provider will rethrow the error.

Implementation

@override
ShieldState build() {
  // A watched-dep change (the session flips) RE-RUNS build() on the SAME
  // notifier, firing the prior cycle's onDispose first → `_disposed` would
  // stick `true` and wedge every later `_set` (#330). Reset it each build;
  // the instance-identity guards on the post-await arms keep the old
  // cycle's in-flight continuations from writing into the new one.
  _disposed = false;
  ref.onDispose(() => _disposed = true);
  // Cached for the actions. The session can legitimately flip to null (the
  // wallet closed) — `build()` re-runs and resets to idle.
  _session = ref.watch(walletSessionProvider);
  return const ShieldIdle();
}