3

I am working with an app in Apache Cordova, but I am not able to get the cookies and retain them from the website I am loading using Inappbrowser. So I switched to flutter where I am able to do the above functionality.

However, I would like the app to behave like an app not like a browser.

Now I am stuck with this problem where the webview_flutter opens either preview popup or an action sheet when the user does a long-press on links.

Please let me know if there is a way to disable the preview popup or opening action sheet when the user does a long-press on links.

I have implemented my Webview as below.

'''

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);
          }),
        );
      }
    }

'''

enter image description here

  • I'm not sure if this helps but I wanted to disable the longPress context menu and finally figured out a way to do it > https://stackoverflow.com/a/66153604/12140067 – Chris Feb 11 '21 at 11:12

1 Answers1

0

AFAIK, there is thread from this open GitHub issue requesting for feature to provide parameter to control or intercept long press events. Although there is a temporary fix that could handle this,

I solved it temporarily by

gestureRecognizers: Platform.isAndroid ? {Factory(() => EagerGestureRecognizer())} : null

It can also affect some gestures as mentioned here:

I tried it and found that it disables swiping and scrolling both

MαπμQμαπkγVπ.0
  • 5,887
  • 1
  • 27
  • 65