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
WalletRescanState build() {
_disposed = false;
ref.onDispose(() => _disposed = true);
// Clear the rebuilding cue once sync reaches the tip — the history has fully
// repopulated. `listen` (not `watch`): this notifier must NOT rebuild on sync
// status (that would reset the cue on every scan tick); it only reacts to the
// reached-tip EDGE. `syncStatusProvider` is itself rebuilt across the session
// swap, but this listen re-registers against the live one, so the post-rescan
// session's UpToDate is what clears the cue.
ref.listen<AsyncValue<SyncStatus>>(syncStatusProvider, (_, next) {
if (state is WalletRescanRebuilding &&
next.value is SyncStatus_UpToDate) {
state = const WalletRescanIdle();
}
});
// Reset when the WALLET ITSELF dies (#380 — the #377 identity leak):
// this presentation describes ONE wallet's recovery, but the controller
// deliberately outlives the session swap, so without this a failure notice
// would outlive a delete, and a Rebuilding banner would render over the
// NEXT wallet's surface until ITS first reached-tip. The no-wallet-on-disk
// phases (Welcome / the restore form, and their in-flight successors) are
// exactly "the wallet this state described is gone". A rescan's own swap
// never leaves Active, so the survive-the-swap guarantee is untouched —
// as is a delete/rescan FAULT recovery (it re-probes back to a
// wallet-holding state without passing through these).
ref.listen<OnboardingState>(onboardingControllerProvider, (_, next) {
final walletGone =
next is OnboardingWelcome ||
next is OnboardingRestoreInput ||
next is OnboardingGenerating ||
next is OnboardingRestoring;
if (walletGone && state is! WalletRescanIdle) {
state = const WalletRescanIdle();
}
});
return const WalletRescanIdle();
}