7

Can I track or detect which button the user pressed in webview and make logical decisions according to that in my flutter app?

I am using webview_flutter package.

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
Farwa
  • 6,156
  • 8
  • 31
  • 46
  • What I would do, if you load a webview that you control, I would add button listeners and once they are clicked, call a method that communicates to your native code in Flutter. [This](https://stackoverflow.com/questions/53689662/flutter-webview-two-way-communication/55114952) can help. – tomerpacific Oct 22 '20 at 05:18
  • I don't have control over the URL that'll be loaded. I'll just have to check cases, like if the certain button is pressed or not. – Farwa Oct 22 '20 at 05:20
  • then I don't think what you are asking is possible. Maybe there is some way to detect UI changes inside the webview for Flutter, but that would require some research. – tomerpacific Oct 22 '20 at 05:23
  • no that certainly is not possible because a webview cannot possibly know where the button is on the web page @tomerpacific 's answer is the only way (try looking for the webage api if they provide one create your own layout) – Aditya Bhawsar Oct 22 '20 at 06:09
  • @Farwa you can achieve it using the Navigation Delegate parameter in the WebView widget. When you tap on webview's button there probably another request URL invoked so you have to just check if that URL is invoked in the navigation delegate if invoked then button is pressed. – Darshan Prajapati Oct 22 '20 at 07:54
  • 1
    Tried. That Navigation Delegate is only been invoked when there's a URL change. @DarshanPrajapati – Farwa Oct 22 '20 at 08:13
  • Any one found solution for this? i have same requirement. Please let me know if we can detect button click from webview? @Farwa – abdulec90 Aug 27 '21 at 11:15
  • I think it will be helpful : https://stackoverflow.com/questions/63365116/how-to-simulate-click-on-button-flutter-webview – jas Nov 23 '22 at 05:32

0 Answers0