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
SwapFlowState 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);
// The wallet-life identity (#381): SAME identity across a rebuild ⇒ a live
// post-commitment swap survives (a rescan swaps the session, not the
// wallet); a DIFFERENT identity ⇒ wipe. Captured on the field so _set
// stamps the CYCLE's identity, never a post-flip read (arch review N1).
final identity = ref.watch(walletIdentityProvider);
_identity = identity;
// Cached for the actions. The session seam can legitimately flip to null (the
// wallet closed) — pre-commitment states reset to a clean form, the honest
// behavior (a swap screen with no live wallet must not hold a stale quote).
_session = ref.watch(walletSessionProvider);
if (identity != _liveIdentity) {
_liveAcrossRebuild = null;
return const SwapFormState();
}
return _liveAcrossRebuild ?? const SwapFormState();
}