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
[webview_flutter] Support settings.setDomStorageEnabled #26347
Comments
Please add the output of To investigate we would need a minimal runnable reproduction Please consider asking support questions in one of the other channels listed at http://flutter.io/support . |
Here's the main.dart // Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
void main() => runApp(MaterialApp(home: WebViewExample()));
class WebViewExample extends StatelessWidget {
final Completer<WebViewController> _controller =
Completer<WebViewController>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter WebView example'),
// This drop down menu demonstrates that Flutter widgets can be shown over the web view.
actions: <Widget>[
NavigationControls(_controller.future),
SampleMenu(_controller.future),
],
),
body: WebView(
initialUrl: 'https://kreatryx.com',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
),
floatingActionButton: favoriteButton(),
);
}
Widget favoriteButton() {
return FutureBuilder<WebViewController>(
future: _controller.future,
builder: (BuildContext context,
AsyncSnapshot<WebViewController> controller) {
if (controller.hasData) {
return FloatingActionButton(
onPressed: () async {
final String url = await controller.data.currentUrl();
Scaffold.of(context).showSnackBar(
SnackBar(content: Text("Favorited $url")),
);
},
child: const Icon(Icons.favorite),
);
}
return Container();
});
}
}
enum MenuOptions {
evaluateJavascript,
toast,
}
class SampleMenu extends StatelessWidget {
SampleMenu(this.controller);
final Future<WebViewController> controller;
@override
Widget build(BuildContext context) {
return FutureBuilder<WebViewController>(
future: controller,
builder:
(BuildContext context, AsyncSnapshot<WebViewController> controller) {
return PopupMenuButton<MenuOptions>(
onSelected: (MenuOptions value) {
switch (value) {
case MenuOptions.evaluateJavascript:
_onEvaluateJavascript(controller.data, context);
break;
case MenuOptions.toast:
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text('You selected: $value'),
),
);
break;
}
},
itemBuilder: (BuildContext context) => <PopupMenuItem<MenuOptions>>[
PopupMenuItem<MenuOptions>(
value: MenuOptions.evaluateJavascript,
child: const Text('Evaluate JavaScript'),
enabled: controller.hasData,
),
const PopupMenuItem<MenuOptions>(
value: MenuOptions.toast,
child: Text('Make a toast'),
),
],
);
},
);
}
void _onEvaluateJavascript(
WebViewController controller, BuildContext context) async {
final String result = await controller
.evaluateJavascript("document.body.style.backgroundColor = 'red'");
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text('JavaScript evaluated, the result is: $result'),
),
);
}
}
class NavigationControls extends StatelessWidget {
const NavigationControls(this._webViewControllerFuture)
: assert(_webViewControllerFuture != null);
final Future<WebViewController> _webViewControllerFuture;
@override
Widget build(BuildContext context) {
return FutureBuilder<WebViewController>(
future: _webViewControllerFuture,
builder:
(BuildContext context, AsyncSnapshot<WebViewController> snapshot) {
final bool webViewReady =
snapshot.connectionState == ConnectionState.done;
final WebViewController controller = snapshot.data;
return Row(
children: <Widget>[
IconButton(
icon: const Icon(Icons.arrow_back_ios),
onPressed: !webViewReady
? null
: () async {
if (await controller.canGoBack()) {
controller.goBack();
} else {
Scaffold.of(context).showSnackBar(
const SnackBar(content: Text("No back history item")),
);
return;
}
},
),
IconButton(
icon: const Icon(Icons.arrow_forward_ios),
onPressed: !webViewReady
? null
: () async {
if (await controller.canGoForward()) {
controller.goForward();
} else {
Scaffold.of(context).showSnackBar(
const SnackBar(
content: Text("No forward history item")),
);
return;
}
},
),
IconButton(
icon: const Icon(Icons.replay),
onPressed: !webViewReady
? null
: () {
controller.reload();
},
),
],
);
},
);
}
} |
What about
Is there more? |
Nope, there is nothing more. This is the same code from the example in webview_flutter directory. Only thing I did is replace "flutter.io" with "kreatryx.com". On iOS it is working but on android it shows blank screen.
|
Please add the output of |
|
Trying a newer Flutter version is likely worth a try.
|
Tried both and it didn't work on any of those channels. This line in the whole log is the root of the issue in my opinion. |
No. The plugin is just a Chrome or Safari browser depending on the platform. |
Try |
Duplicate of #25351 |
I've tried that already. Could you please try it on your computer, because our website run on mobile browser alright. It's just this plugin and that too only on android that we are facing this issue. |
Edit: Just saw that you did in the snippet you posted, disregard this comment. |
Can you reproduce on Android, iOS, or both? |
Yes exactly! That's the issue. Is there any way to implement this java code |
I guess this will require a Pull Request. |
Could you please implement that in the flutter webview example? |
For a short-term fix, you'll probably need to do that yourself. |
@amsmu You could also use flutter_webview_plugin. That one has support for local storage. It is not the 'official' plugin, but it is more mature at the moment. |
@wouterhardeman Yup, that's my only option for time being. I wanted to stay away from it because it creates an overlay on flutter app, hence preventing any flutter UI elements such as snackbar or alert dialog to be rendered over it. |
webview_flutter is not compatible with Android, it block my release schedule.
|
@huuang Do you have an actual error for us? If it is not related, please file a new issue explaining your error. |
|
@wouterhardeman Please see this issue: #27285 (comment) |
Issue isn't reproduced on flutter doctor -v
Code Sample
Could everyone who still has this problem please file a new issue with the exact descriptions what happens, logs and the output of 'flutter doctor -v' please. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to Reproduce
Logs
The text was updated successfully, but these errors were encountered: