Skip to content

v1: Canvas.capture(), canvas draw images, GestureDetector right-click pan updates. #5444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 41 commits into from
Aug 9, 2025

Conversation

FeodorFitsner
Copy link
Contributor

@FeodorFitsner FeodorFitsner commented Jul 14, 2025

Close #5434
Close #3572
Close #5083
Close #3572
Fix #1791

Summary by Sourcery

Enable canvas capture and image shape support, add right-click pan events to GestureDetector, integrate custom Msgpack encoder, and apply various utility and housekeeping improvements

New Features:

  • Implement Canvas.capture, get_capture, and clear_capture methods with image rendering support
  • Add Image shape to Canvas with asynchronous image loading and hashing
  • Introduce on_right_pan_start, on_right_pan_update, and on_right_pan_end events for right-click panning in GestureDetector
  • Integrate custom FletMsgpackEncoder for extended Msgpack serialization in JS and WebSocket backends
  • Expose capture and clear_capture methods in Python Canvas control and add Python Canvas Image shape class

Enhancements:

  • Remove unused imports and parameters in Markdown and Image controls and adjust buildImage signature
  • Fix case-sensitive control type matching for Container and Image in size constraints
  • Update default pageUrl scheme to http in client main.dart and reorder flet_charts import
  • Add fnv1aHash utility for image hashing

Other canvas changes:
- canvas drawing is clipped
- canvas size is stretched to maximum if `expand` is set
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

Copy link

cloudflare-workers-and-pages bot commented Jul 15, 2025

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: e67d21b
Status: ✅  Deploy successful!
Preview URL: https://3c00c317.flet-docs.pages.dev
Branch Preview URL: https://feodor-v1-canvas-recording.flet-docs.pages.dev

View logs

@ndonkoHenri ndonkoHenri linked an issue Aug 1, 2025 that may be closed by this pull request
1 task
@ndonkoHenri ndonkoHenri mentioned this pull request Aug 1, 2025
1 task
Added documentation files for KeyboardListener and related key event types. Updated mkdocs navigation to include new docs. Enhanced docstrings for canvas capture methods and removed redundant event handler argument descriptions in GestureDetector and KeyboardListener.
Added a new example 'detect_keys.py' demonstrating keyboard event handling. Updated documentation to include the example and enhanced event class docstrings for clarity in 'keyboard_listener.py'.
Added comprehensive docstrings to PageView, PageMediaData, and PageResizeEvent for improved clarity and developer guidance. Changed PageView to inherit from ScrollableControl and AdaptiveControl, and updated the import accordingly. Expanded property documentation and clarified usage of key attributes.
PageView no longer inherits from ScrollableControl, and related imports were removed. Page now calls PageView's __post_init__ instead of AdaptiveControl's. This refactoring clarifies class responsibilities and streamlines control hierarchy.
Refactored Python integration tests to use a shared flet_app fixture via conftest.py, reducing code duplication. Added comprehensive canvas control tests with golden image comparisons and supporting assets. Updated canvas text rendering to use 'value' instead of 'text'. Improved tester service and Flutter tester API for more flexible duration handling. Enhanced FastAPI web server integration and updated documentation for new environment variables.
Changed the pytest log_cli_level from DEBUG to INFO in the AppVeyor configuration to reduce log verbosity during integration tests.
Commented out most build and test jobs in .appveyor.yml, limiting test execution to test_finders.py. Increased the test app window width from 400 to 800 in finders.py. Added a pump delay in test_find_by_text to improve test reliability.
The AppVeyor configuration now runs only the test_canvas.py integration test instead of the entire directory. Additionally, the delay in the test_draw_url_image test was increased from 3000ms to 5000ms, likely to improve test reliability.
Replaces the 'delay' parameter with 'pump_times' and 'pump_duration' in canvas integration tests and the FletTestApp helper. This allows for more precise control over test timing and screenshot capture during automated UI tests.
Introduces integration tests for the Canvas control's capture functionality, including new golden images for macOS. Fixes a bug in Canvas.clear_capture_async() to call the correct method, and moves screenshot pixel ratio and similarity threshold to FletTestApp instance variables. Also enables all previously commented-out jobs in the AppVeyor CI matrix.
Introduces a new build() method for control child initialization, refactors property handling using _internals for host_expanded, host_positioned, and skip_properties, and updates Dart logic to use these internals for sizing and positioning. Updates tests and removes obsolete _skip_inherited_notifier logic. This change improves extensibility and consistency in control property management.
@FeodorFitsner FeodorFitsner changed the title v1: Canvas.capture() and GestureDetector right-click pan updates. v1: Canvas.capture(), canvas draw images, GestureDetector right-click pan updates. Aug 8, 2025
Introduces an optional pixel_ratio argument to Canvas.capture and Canvas.capture_async, allowing control over the resolution of captured images. Updates the Dart backend to use the provided pixel ratio and adjusts integration tests and Python examples to use the new build method instead of init.
@ndonkoHenri ndonkoHenri requested a review from Copilot August 8, 2025 23:15
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements Canvas capture functionality, adds image shape support to Canvas, introduces right-click pan events for GestureDetector, and integrates a custom Msgpack encoder with various testing and infrastructure improvements.

  • Implements Canvas.capture(), get_capture(), and clear_capture() methods with image rendering support
  • Adds Image shape to Canvas with asynchronous image loading and hashing
  • Introduces right-click pan events (on_right_pan_start, on_right_pan_update, on_right_pan_end) for GestureDetector
  • Integrates custom FletMsgpackEncoder for extended Msgpack serialization
  • Adds KeyboardListener control with key down/up/repeat event handling

Reviewed Changes

Copilot reviewed 74 out of 98 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
sdk/python/packages/flet/src/flet/controls/base_control.py Adds event triggering logic and build() method lifecycle
sdk/python/packages/flet/src/flet/controls/core/canvas/canvas.py Implements canvas capture methods with async image rendering
sdk/python/packages/flet/src/flet/controls/core/canvas/image.py New Canvas Image shape class for drawing images
sdk/python/packages/flet/src/flet/controls/core/gesture_detector.py Adds right-click pan event properties
sdk/python/packages/flet/src/flet/controls/core/keyboard_listener.py New KeyboardListener control for key event handling
packages/flet/lib/src/controls/canvas.dart Canvas implementation with capture, image loading, and dash pattern support
packages/flet/lib/src/controls/keyboard_listener.dart Flutter KeyboardListener widget implementation

FeodorFitsner and others added 9 commits August 8, 2025 17:10
Introduced a 'Save image' button that allows users to save the canvas as a PNG file. Optimized the brush drawing by batching shape captures every 30 shapes, clearing the canvas after each capture, and improved state management using a dataclass. Also updated the canvas background to white and added a border for better visibility.
Updated all canvas shape and path constructors in example files to use explicit keyword arguments for clarity and consistency. Added documentation for the Image control and updated the canvas documentation index to include gradients and the new Image page.
Introduced platform-specific validation in FilePicker: 'get_directory_path' now raises NotImplementedError on web, and 'save_file' raises ValueError if required arguments are missing on web, iOS, or Android. Updated docstrings to clarify argument requirements and platform behavior.
Eliminated the code path that attempted to decode the image source as base64 when 'src' is provided. Now, an exception is thrown if neither 'src' nor 'src_bytes' is present, clarifying the expected input and simplifying image loading logic.
@FeodorFitsner FeodorFitsner merged commit 3b4447b into main Aug 9, 2025
3 checks passed
@FeodorFitsner FeodorFitsner deleted the feodor/v1-canvas-recording branch August 9, 2025 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants