0

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

1 Answer 1

0
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');
              """);
            },
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.