Sando Philip
Sando Philip

Reputation: 1

How to hide link in flutter in app webview?

I was using the flutter_inappwebview: ^6.1.5 to make a PWA app using a react frame work. There is several link button which are connecting to many pages and i couldnt hide these link when i long press a button it shows the link and i can even also drag and drop the link how can i actully hide that from flutter

import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:get/get.dart';
import 'package:workreport/controller/webViews.dart';

class HomeViews extends StatelessWidget {
  final WebViewController webViewCtrl = Get.put(WebViewController());

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: webViewCtrl.handleBackNavigation,
      child: Scaffold(
        body: SafeArea(
          child: InAppWebView(
            initialUrlRequest: URLRequest(url: WebUri('https://example.com')),
            initialSettings: InAppWebViewSettings(
              javaScriptEnabled: true,
              javaScriptCanOpenWindowsAutomatically: true,
              cacheEnabled: true,
              clearCache: false,
              thirdPartyCookiesEnabled: true,
              verticalScrollBarEnabled: false,
              disableVerticalScroll: false,
              disableHorizontalScroll: true,
              disableContextMenu: true,
              disableLongPressContextMenuOnLinks: true,
              overScrollMode: OverScrollMode.NEVER,
              builtInZoomControls: false,
              displayZoomControls: false,
              maximumZoomScale: 1,
              minimumZoomScale: 1,
              supportZoom: false,
            ),
            onWebViewCreated: (InAppWebViewController controller) {
              webViewCtrl.webViewController = controller;
            },
            pullToRefreshController: webViewCtrl.pullToRefreshController,
            onLoadStop: (controller, url) {
              webViewCtrl.endRefreshing();
            },
            onReceivedError: (controller, request, error) {
              webViewCtrl.endRefreshing();
            },
            onProgressChanged: (controller, progress) {
              if (progress == 100) {
                webViewCtrl.endRefreshing();
              }
            },
          ),
        ),
      ),
    );
  }
}

Upvotes: 0

Views: 86

Answers (1)

shivraj walke
shivraj walke

Reputation: 31

onLoadStop: (controller, url) async {
              webViewCtrl.endRefreshing();
              
              await controller.evaluateJavascript(source: """
                // Hide a link by URL
                document.querySelectorAll('a[href="https://example-link-to-hide.com"]').forEach(el => el.style.display = 'none');
                
                // Hide links by class
                document.querySelectorAll('.hide-this-link').forEach(el => el.style.display = 'none');
              """);
            },

Upvotes: 0

Related Questions