build method

Initialize an AsyncNotifier.

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

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

If this method throws or returns a future that fails, the error will be caught and an AsyncError will be emitted.

Implementation

@override
Future<DeepScanRestoreNoteState> build() async {
  // Re-read on an identity change. The controller AWAITS the note write
  // BEFORE it flips the session to OnboardingActive, so by the time
  // that flip rebuilds this provider the store already holds the fresh value
  // — no write/flip race. Belt: the note is only RENDERED after the first
  // catch-up (WalletCatchUpNone in wallet_screen), long after that write, so
  // even a watcher that read earlier would still resolve correctly. A
  // silently-lost write (the setter never throws) reads notApplicable ⇒ no
  // note (fail-safe). The catch-up gate only delays RENDERING, not this read.
  ref.watch(walletSessionProvider);
  final store = ref.watch(onboardingStoreProvider);
  if (store == null) return DeepScanRestoreNoteState.notApplicable;
  try {
    return await store.deepScanRestoreNoteState();
  } catch (_) {
    return DeepScanRestoreNoteState.notApplicable;
  }
}