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

Dont pass around BuildContext for making snackbars #292

Open
JAicewizard opened this issue Nov 15, 2022 · 2 comments
Open

Dont pass around BuildContext for making snackbars #292

JAicewizard opened this issue Nov 15, 2022 · 2 comments
Labels
chore Something that is not a bug or a feature, does not change production behaviour easy and fun Good for newcomers priority: low Should be dealt with when nothing else remains.

Comments

@JAicewizard
Copy link
Contributor

JAicewizard commented Nov 15, 2022

What

Use a GlobalKey<ScaffoldMessengerState> instead of passing around a BuildContext

Why

BuildContext can expire, and although it is possible to avoid using an expired BuildContext we don't know if the scaffold is still alive at the time of calling a snackbar.

How

https://github.com/flutter/flutter/blob/master/examples/api/lib/material/scaffold/scaffold_messenger.of.1.dart

@JAicewizard JAicewizard added priority: low Should be dealt with when nothing else remains. chore Something that is not a bug or a feature, does not change production behaviour easy and fun Good for newcomers labels Nov 15, 2022
@DeD1rk
Copy link
Member

DeD1rk commented Nov 25, 2022

That solution actually requires passing down the globalkey all over the widget tree, or lookign it up using another context. So it doesn't really help when compared to looking up from context synchronously.

@JAicewizard
Copy link
Contributor Author

Yeah but in most cases its just in the widget itself, when its available its probably better to do this as its also faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Something that is not a bug or a feature, does not change production behaviour easy and fun Good for newcomers priority: low Should be dealt with when nothing else remains.
Projects
None yet
Development

No branches or pull requests

2 participants