-
Notifications
You must be signed in to change notification settings - Fork 939
Closed
Description
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.
Metadata
Metadata
Assignees
Labels
No labels