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

How to get Scaffold context inside of _view? #13

Closed
ValeriusGC opened this issue Aug 8, 2019 · 1 comment
Closed

How to get Scaffold context inside of _view? #13

ValeriusGC opened this issue Aug 8, 2019 · 1 comment

Comments

@ValeriusGC
Copy link

Hello, i have no idea how to catch Scaffold from context in this situation:

Widget _view(
    BuildContext ctx, Dispatch<CaseEdMsg> dispatch, CaseEdModel model) {
  return Scaffold(
    appBar: AppBar(
      title: Text('Editor'),
    ),
    body: Container(
      padding: EdgeInsets.all(8),
      child: SomeButton(
          onPressed: () {
               Scaffold.of(ctx).showSnackBar(); /// Here
          },
);

Where can i intercept Scaffold?

@p69
Copy link
Owner

p69 commented Aug 8, 2019

Hi, it could be a bit tricky.

Option 1: use GlobalKey. You can create top-level (or in upper level) global key for Scaffold, and then you have access to widget's state or widget itself.

Option 2: As I did in ToDo App example. You can save reference to Scaffold state and use it later. I also did it for showing Snackbar.

It looks like option 1 is proper way to do it.

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