flet icon indicating copy to clipboard operation
flet copied to clipboard

feat: `WebView` enhancements

Open ndonkoHenri opened this issue 1 year ago • 6 comments

Summary by Sourcery

Enhance the WebView component with new event handling and method support, refactor platform detection logic, and update dependencies for improved platform-specific functionality.

New Features:

  • Introduce new event handling capabilities for the WebView component, including scroll, console message, and JavaScript alert dialog events.
  • Add support for various WebView methods such as reload, go back, go forward, enable/disable zoom, clear cache, and run JavaScript.
  • Implement platform-specific WebView support for mobile, macOS, web, Windows, and Linux platforms.

Enhancements:

  • Deprecate the 'javascript_enabled' property in favor of 'enable_javascript' in the WebView component.
  • Refactor platform detection logic by introducing a new 'platform.dart' utility for better platform-specific checks.

Build:

  • Update dependencies in the pubspec.yaml file, including upgrading 'webview_flutter' and adding new dependencies like 'webview_flutter_web' and 'webview_flutter_platform_interface'.

ndonkoHenri avatar Sep 20 '24 09:09 ndonkoHenri

Reviewer's Guide by Sourcery

This pull request introduces significant enhancements to the WebView component in the Flet framework, improving its functionality across different platforms (mobile, web, and desktop). The changes include new features, better platform support, and code refactoring for improved maintainability.

File-Level Changes

Change Details Files
Enhanced WebView functionality with new methods and events
  • Added new methods like reload(), can_go_back(), can_go_forward(), go_back(), go_forward()
  • Implemented new events such as on_progress, on_url_change, on_scroll, on_console_message
  • Added support for JavaScript execution and HTML loading
  • Implemented methods for cache and local storage clearing
sdk/python/packages/flet-core/src/flet_core/webview.py
Improved cross-platform support for WebView
  • Created separate implementations for mobile/macOS, web, and Windows/Linux platforms
  • Implemented platform-specific checks to use appropriate WebView implementation
  • Added new utility functions for platform detection
packages/flet_webview/lib/src/webview_mobile_and_mac.dart
packages/flet_webview/lib/src/webview_web.dart
packages/flet_webview/lib/src/webview_windows_and_linux.dart
packages/flet/lib/src/utils/platform.dart
Refactored existing code for better maintainability
  • Moved platform-specific utility functions from desktop.dart to platform.dart
  • Updated import statements across multiple files to use the new platform.dart
  • Refactored WebView control to use the new platform-specific implementations
packages/flet/lib/src/utils/desktop.dart
packages/flet/lib/src/controls/webview.dart
packages/flet/lib/src/controls/page.dart
packages/flet/lib/src/controls/grid_view.dart
packages/flet/lib/src/controls/list_view.dart
packages/flet/lib/src/controls/scrollable_control.dart
Updated dependencies and configurations
  • Added new WebView-related dependencies in pubspec.yaml
  • Updated iOS and macOS configurations for WebView support
packages/flet_webview/pubspec.yaml
client/ios/Runner/AppDelegate.swift
client/macos/Flutter/GeneratedPluginRegistrant.swift

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

sourcery-ai[bot] avatar Sep 20 '24 09:09 sourcery-ai[bot]

Kindly merge and one more thing add permission in manifest for Android to display local html files in web view

Summary by Sourcery

Enhance the WebView component with new event handling and method support, refactor platform detection logic, and update dependencies for improved platform-specific functionality.

New Features:

  • Introduce new event handling capabilities for the WebView component, including scroll, console message, and JavaScript alert dialog events.
  • Add support for various WebView methods such as reload, go back, go forward, enable/disable zoom, clear cache, and run JavaScript.
  • Implement platform-specific WebView support for mobile, macOS, web, Windows, and Linux platforms.

Enhancements:

  • Deprecate the 'javascript_enabled' property in favor of 'enable_javascript' in the WebView component.
  • Refactor platform detection logic by introducing a new 'platform.dart' utility for better platform-specific checks.

Build:

  • Update dependencies in the pubspec.yaml file, including upgrading 'webview_flutter' and adding new dependencies like 'webview_flutter_web' and 'webview_flutter_platform_interface'.

Any update???

Any update?

Is there any chance for supporting WebView CookieManager ?

kalatawei avatar Oct 29 '24 19:10 kalatawei

This looks great! Can't wait to implement this in my project once it gets merged to main!!

cayubweeums avatar Nov 06 '24 17:11 cayubweeums

@sourcery-ai review

ndonkoHenri avatar Nov 07 '24 00:11 ndonkoHenri

Is it merged and working on desktop??

Have documentation updated in flet docs?

Working on it.

ndonkoHenri avatar Nov 10 '24 10:11 ndonkoHenri

Good stuff @ndonkoHenri 😎! But i have some questions, are we going to get the run_javascripts() methods support on other platforms soon? I thought this PR would add WV support for the windows,

Benitmulindwa avatar Nov 10 '24 20:11 Benitmulindwa

Windows and Linux are not yet supported. Will have a look at them after we release 0.25.0.

ndonkoHenri avatar Nov 10 '24 21:11 ndonkoHenri

Would be great to have the run_javascripts() method on Web too

Edit: Am not able to update the url value when running on web. Is it a bug or that’s how it’s supposed to be?

Benitmulindwa avatar Nov 11 '24 06:11 Benitmulindwa

Am able to change the url value outside of a function,… but once am inside a function/eventhandler an error is shown saying that the method is supported on Android, iOS and macOS only.

Benitmulindwa avatar Nov 11 '24 12:11 Benitmulindwa

@Benitmulindwa let's continue this in a new discussion. Can you create one and explain the issues you face?

ndonkoHenri avatar Nov 11 '24 13:11 ndonkoHenri

@ndonkoHenri all right lemme do it

Benitmulindwa avatar Nov 11 '24 16:11 Benitmulindwa

#4356

Benitmulindwa avatar Nov 11 '24 16:11 Benitmulindwa

On Windows, an error is reported: Webview is not yet supported on this Platform.

pychans avatar Nov 29 '24 00:11 pychans

Windows and Linux support is still to be added.

ndonkoHenri avatar Nov 29 '24 09:11 ndonkoHenri

@ndonkoHenri Hello, I attempted to run WebView on the Android platform, but found that it couldn't execute JavaScript. This issue doesn't exist on the web platform. Could you please tell me what might be the reason for this? flet==0.27.6 flet-webview==0.1.0 python==3.12 Android version 12

lgs888 avatar May 08 '25 02:05 lgs888

Kindly implemented refresh or reload method in flet also for reloading current screen