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

WebViewScaffold should extend Scaffold, else snackbars, alertdialogs etc cannot be used. #69

Closed
MaskyS opened this issue Apr 25, 2018 · 3 comments

Comments

@MaskyS
Copy link

MaskyS commented Apr 25, 2018

While using Widget Webview, it is not possible to show AlertDialogs or SnackBars or ModalBottomSheets.

For instance, to show a snackbar, we'd either use Scaffold.of(context).showSnackBar(new SnackBar(...)...); or the method below:

              return new WebviewScaffold(
                key: _webViewScaffoldKey,
                userAgent: userAgentString,
                url: _getSubjectUrl(value),
                appBar: new StudentoAppBar(actions: <Widget>[
                  new IconButton(
                    icon: new Icon(Icons.file_download),
                    color: Colors.white,
                    onPressed: () {
                      _webViewScaffoldKey.currentState.showSnackBar(new SnackBar(
                        content: new Text("Sample text!"),
                        duration: new Duration(seconds: 5),
                        action: new SnackBarAction(
                          label: "CLICK ME",
                          onPressed: _clickedMe,
                        ),
                      ),);},
                  ),
                ],),
                withLocalStorage: true,
              );

These give errors:
1)

I/flutter ( 4430): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter ( 4430): The following NoSuchMethodError was thrown while handling a gesture:
I/flutter ( 4430): The method 'showSnackBar' was called on null.
I/flutter ( 4430): Receiver: null
I/flutter ( 4430): Tried calling: showSnackBar(Instance of 'SnackBar')
I/flutter ( 4430):

and 2)

I/flutter ( 4430): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter ( 4430): The following assertion was thrown while handling a gesture:
I/flutter ( 4430): Scaffold.of() called with a context that does not contain a Scaffold.
I/flutter ( 4430): No Scaffold ancestor could be found starting from the context that was passed to Scaffold.of(). This
I/flutter ( 4430): usually happens when the context provided is from the same StatefulWidget as that whose build
I/flutter ( 4430): function actually creates the Scaffold widget being sought.
I/flutter ( 4430): There are several ways to avoid this problem. The simplest is to use a Builder to get a context that
I/flutter ( 4430): is "under" the Scaffold. For an example of this, please see the documentation for Scaffold.of():
I/flutter ( 4430):   https://docs.flutter.io/flutter/material/Scaffold/of.html
I/flutter ( 4430): A more efficient solution is to split your build function into several widgets. This introduces a
I/flutter ( 4430): new context from which you can obtain the Scaffold. In this solution, you would have an outer widget
I/flutter ( 4430): that creates the Scaffold populated by instances of your new inner widgets, and then in these inner
I/flutter ( 4430): widgets you would use Scaffold.of().
I/flutter ( 4430): A less elegant but more expedient solution is assign a GlobalKey to the Scaffold, then use the
I/flutter ( 4430): key.currentState property to obtain the ScaffoldState rather than using the Scaffold.of() function.
I/flutter ( 4430): The context used was:
I/flutter ( 4430):   Builder
I/flutter ( 4430):
I/flutter ( 4430): When the exception was thrown, this was the stack:
I/flutter ( 4430): #0      Scaffold.of (package:flutter/src/material/scaffold.dart:944:5)

But both do not work. As for AlertDialog it is displayed behind this scaffold. I think that this is because WebviewScaffold extends StatefulWidget instead of Scaffold. Please fix.

@lejard-h
Copy link
Collaborator

It won't be possible, the webview is not inside the widget tree, it is on top of the scaffold, so all snackbar or alert dialog will appear under the webview

@MaskyS
Copy link
Author

MaskyS commented Apr 27, 2018

Wouldn't the inability to show snackbars, dialogs etc in a webView still be considered a bug/issue? These elements are supposed to be above almost everything else according to material guidelines: https://material.io/guidelines/components/snackbars-toasts.html#

@lejard-h
Copy link
Collaborator

This is technically impossible, the webview is not inside flutter but on top of it.

See this for inline webview, flutter/flutter#730

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