我正在使用 Apache Cordova 中的应用程序,但我无法从使用 Inappbrowser 加载的网站获取 cookie 并保留它们。因此,我切换到能够执行上述功能的颤振。
但是,我希望该应用程序表现得像一个应用程序而不是浏览器。
现在我遇到了这个问题,当用户长按链接时, webview_flutter打开预览弹出窗口或操作表。
请让我知道当用户长按链接时是否有办法禁用预览弹出窗口或打开操作表。
我已经实现了我的 Webview,如下所示。
'''
class _WebViewExampleState extends State<WebViewExample> {
final Completer<WebViewController> _controller =
Completer<WebViewController>();
final cookieManager = WebviewCookieManager();
SharedPreferences prefs;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Builder(builder: (BuildContext context) {
return WebView(
gestureRecognizers: null,
initialUrl: url,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) async {
print('WebView Created');
_controller.complete(webViewController);
prefs = await SharedPreferences.getInstance();
String cookie = prefs.getString('cookieList');
List<Cookie> cookies = [];
for (Map item in jsonDecode(cookie)) {
print(item);
String name = item['name'];
String value = item['value'];
String domain = item['domain'];
DateTime expires = item['expires'];
bool httpOnly = item['httpOnly'];
int maxAge = item['maxAge'];
String path = item['path'];
bool secure = item['secure'];
cookies.add(Cookie(name, value)
..domain = domain
..expires = expires
..httpOnly = httpOnly
..maxAge = maxAge
..path = path
..secure = secure);
}
await cookieManager.setCookies(cookies);
},
onPageStarted: (String url) async {
print('Page started loading: $url');
},
onPageFinished: (String url) async {
print('Page finished loading: $url');
final cookies = await cookieManager.getCookies(url);
print(cookies);
List cookieList = [];
for (var item in cookies) {
Map<String, dynamic> cookie = {};
cookie['domain'] = item.domain;
cookie['name'] = item.name;
cookie['value'] = item.value;
cookie['expires'] = item.expires;
cookie['httpOnly'] = item.httpOnly;
cookie['maxAge'] = item.maxAge;
cookie['path'] = item.path;
cookie['secure'] = item.secure;
cookieList.add(cookie);
}
prefs.setString('cookieList', json.encode(cookieList));
},
gestureNavigationEnabled: false);
}),
);
}
}
'''