flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.79k stars 27.16k forks source link

Android Unable to show clipboard menu such as copy or paste in webview #153676

Closed AravindhKnightDev closed 1 day ago

AravindhKnightDev commented 3 weeks ago

Steps to reproduce

Screenshot 2024-08-19 at 12 28 00 PM

https://github.com/user-attachments/assets/ccab6cae-d235-4214-b62e-1ef17cfb7517

Flutter 3.24.0 Dart 3.5.0

clipboard menu works on iOS but not working on android.

Expected results

Actual results

The clipboard menu works on iOS but not working on android.

Code sample

Code sample ```dart class PaymentScreenBody extends StatelessWidget { const PaymentScreenBody({super.key}); @override Widget build(BuildContext context) { final PaymentSubscribeViewModel viewModel = ViewModel.watch(context); return WebViewWidget( controller: viewModel.webController ..setJavaScriptMode(JavaScriptMode.unrestricted) ..setBackgroundColor(const Color(0x00000000)) ..setNavigationDelegate( NavigationDelegate( onPageStarted: (String url) {}, onPageFinished: (String url) { viewModel.paymentRedirection(url); }, onHttpError: (HttpResponseError error) {}, onWebResourceError: (WebResourceError error) {}, onNavigationRequest: (NavigationRequest request) { return NavigationDecision.navigate; }, ), ) ..loadRequest(Uri.parse(viewModel.paymentUrl.toString()))); } } ```

Screenshots or Video

Screenshots / Video demonstration [https://github.com/user-attachments/assets/ccab6cae-d235-4214-b62e-1ef17cfb7517]

Logs

Logs ```console ```

Flutter Doctor output

Doctor output ```console ```
huycozy commented 3 weeks ago

Hi @AravindhKnightDev Which webview_flutter version are you using? Please share the correct demo screenshot as I see you provided iOS screenshot but you mentioned the issue occurs on Android.

I checked this issue using below minimal sample code on Android but the clipboard menu is showing as desired:

Demo
Sample code ```dart import 'package:flutter/material.dart'; import 'package:webview_flutter/webview_flutter.dart'; void main() => runApp(const MaterialApp(home: WebViewExample())); class WebViewExample extends StatefulWidget { const WebViewExample({super.key}); @override State createState() => _WebViewExampleState(); } class _WebViewExampleState extends State { late final WebViewController controller; @override void initState() { super.initState(); controller = WebViewController() ..setJavaScriptMode(JavaScriptMode.unrestricted) ..setBackgroundColor(const Color(0x00000000)) ..setNavigationDelegate( NavigationDelegate( onProgress: (int progress) { // Update loading bar. }, onPageStarted: (String url) {}, onPageFinished: (String url) {}, onWebResourceError: (WebResourceError error) {}, ), ) ..loadRequest(Uri.parse('https://flutter.dev/')); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Flutter Simple Example')), body: WebViewWidget(controller: controller), ); } } ```

Please try this sample code on your end and confirm.

AravindhKnightDev commented 3 weeks ago

Hi @huycozy

I'm using webview_flutter: ^4.8.0. As you mentioned, the clipboard menu works for text but not for images. Could you please test this with images as well? I’ve already provided a screenshot and video for reference. But in android, i want it like this Screenshot 2024-08-20 at 4 37 52 PM

You can use the following demo sandbox link to test the issue with images: https://demo.juz4x.com/hitpay/pay.php

huycozy commented 3 weeks ago

The link you provided above requires input sensitive info so I use this link with a direct image instead: https://github.com/marketplace/models.

Can you please confirm if it works on Android native example or other Android apps? I checked this on Android pure WebView below but the clipboard also doesn't show up as well:

<WebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
binding.webView.loadUrl("https://github.com/marketplace/models")

That means this seems to be infeasible on Android as my understanding.

github-actions[bot] commented 1 day ago

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones. Thanks for your contribution.