Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about use of Future Signal. #267

Closed
iSaqibShafique opened this issue May 20, 2024 · 7 comments
Closed

Question about use of Future Signal. #267

iSaqibShafique opened this issue May 20, 2024 · 7 comments
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@iSaqibShafique
Copy link

iSaqibShafique commented May 20, 2024

If we need to change the value of FutureSignal then how we can do this,I have searched all across the web, but haven't find any solution, like this.

FutureSignal<SignupStatus> loginSignal =
      FutureSignal(() async => SignupStatus.initial, autoDispose: true);

  void login(BuildContext context,
      {required String email, required String password}) {
    if (key.currentState!.validate()) {
      loginSignal = FutureSignal(() async {
        FirebaseAuth auth = FirebaseAuth.instance;
        UserCredential cred = await auth.createUserWithEmailAndPassword(
            email: email, password: password);
        if (cred.user != null) {
          await cred.user!.sendEmailVerification();
          // ignore: use_build_context_synchronously
          GoRouter.of(context).pushReplacementNamed(AppRoutes.emailverification,
              extra: {"user": cred.user});
          return SignupStatus.success;
        } else {
          return SignupStatus.error;
        }
      });
    }
@rodydavis
Copy link
Owner

Why not put that logic inside the future signal? This is create a new signal every time that will break subscribers.

If you want to do it manually there is also AsyncSignal

@rodydavis rodydavis added the documentation Improvements or additions to documentation label May 20, 2024
@rodydavis rodydavis changed the title Incomplete documentation of Future Signal. Question about use of Future Signal. May 20, 2024
@iSaqibShafique
Copy link
Author

@rodydavis

Why I'm getting this error :

flutter: signal warning: [4|null] has been read after disposed: #0 Signal.value (package:signals_core/src/core/signal.dart:292:97)
#1 watchSignal (package:signals_flutter/src/watch/extension.dart:10:46)
#2 FlutterReadonlySignalUtils.watch (package:signals_flutter/src/extensions/signal.dart:15:12)
#3 _EmailSignupState.intialState (package:dating/view/email_signup/view.dart:108:50)
#4 _EmailSignupState.build. (package:dating/view/email_signup/view.dart:71:22)
#5 _WatchState.rebuild (package:signals_flutter/src/watch/widget.dart:196:34)
#6 _WatchState.build. (package:signals_flutter/src/watch/widget.dart:219:11)
#7 Effect._callback (package:signals_core/src/core/effect.dart:350:32)
#8 _endBatch (package:signals_core/src/core/batch.dart:29:18)
#9 Signal.set (package:signals_core/src/core/signal.dart:269:9)
#10 Signal.value= (package:signals_core/src/core/signal.dart:284:5)
#11 EmailSignupController.onRet<…>

When doing these changes : void onRetry() {
loginSignal.value = const AsyncData(null);
}

@rodydavis
Copy link
Owner

Because autoDispose is set to true, try removing that

@iSaqibShafique
Copy link
Author

Same issue, I've tried removing autoDispose and set the autoDispose to false, but same issue occurs.

@rodydavis
Copy link
Owner

Can you provide a minimal code example to reproduce the issue?

@rodydavis
Copy link
Owner

Also try hot restart instead of hot reload to see if the issue still persists

@rodydavis rodydavis added the question Further information is requested label May 23, 2024
@rodydavis
Copy link
Owner

If you are looking to pass args to update a future signal then you need to use computedAsync and computedFrom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants