Skip to content

Unhandled Exception: Bad state: Tried to use ProfileUserStateNotifier after dispose was called. #1110

Answered by huzzi
huzzi asked this question in Q&A
Discussion options

You must be logged in to vote

Solved it using the code below, once issue is that the api is called twice for some reason when the FirestoreUser is updated.

final profileAsyncController =
    StateNotifierProvider<ProfileAsyncNotifier, AsyncValue<ProfileUser?>>(
        (ref) => ProfileAsyncNotifier(ref));

class ProfileAsyncNotifier extends StateNotifier<AsyncValue<ProfileUser?>> {
  ProfileAsyncNotifier(this.ref) : super(AsyncLoading()) {
    _init();
  }

  final Ref ref;

  void _init() async {
    final firestoreUser = ref.watch(firestoreUserChangeProvider);

    var profile = await ref.read(apiServiceProvider)!.getProfile();
    state = AsyncData(profile);

    final firestoreDb = ref.read(firestoreDatabaseProvid…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by huzzi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant