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

show dialog/snackbar etc #38

Closed
smiLLe opened this issue Jan 24, 2019 · 4 comments
Closed

show dialog/snackbar etc #38

smiLLe opened this issue Jan 24, 2019 · 4 comments

Comments

@smiLLe
Copy link
Contributor

smiLLe commented Jan 24, 2019

Hi, great lib, i love it :D!

I am wondering what is the best/recommended way to show a dialog/navigate in response to some state change.
int state = useStream(myStream); if (state == 5) { showDialog(context: context ....); }

@smiLLe
Copy link
Contributor Author

smiLLe commented Jan 24, 2019

i could do
useEffect(() { if (state == 5) { showDialog( context:context ); } }, [state] );
is it valid to use context in useEffect?

@rrousselGit
Copy link
Owner

No this won't do.
We need a useAsyncEffect, which calls the callback after the build finished.

A lazy implementation could be:

void useAsyncEffect(VoidCallback cb, [List<dynamic> keys]) {
  useEffect(() => Future.microtask(cb), keys);
}

@smiLLe
Copy link
Contributor Author

smiLLe commented Jan 24, 2019

WidgetsBinding.instance.addPostFrameCallback(); won't work, i guess :)?

@rrousselGit
Copy link
Owner

It will. There's nothing wrong with it.

You can use context too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants