-
Notifications
You must be signed in to change notification settings - Fork 599
refactor!: consolidate src_base64, src, and src_bytes into unified/intelligent src prop
#5817
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @ndonkoHenri, your pull request is larger than the review limit of 150000 diff characters
There was a problem hiding this 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 consolidates three separate properties (src, src_base64, src_bytes) into a single intelligent src property that can automatically detect and handle URLs, file paths, base64-encoded strings, and raw bytes. This is a breaking change that simplifies the API across multiple controls (Image, Lottie, Audio, CircleAvatar, DecorationImage, Canvas.Image).
Key changes:
- Python API now uses
Union[str, bytes]for thesrcproperty - Dart implementation uses
ResolvedAssetSourceutility to intelligently parse the source - Documentation and examples updated to reflect the unified API
- Tests updated to use the new consolidated property
Reviewed Changes
Copilot reviewed 32 out of 33 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
circle_avatar.py |
Changed foreground_image_src and background_image_src to accept Union[str, bytes] |
bottom_sheet.py |
Documentation improvement (unrelated to main change) |
image.py |
Removed src_base64 and src_bytes, consolidated into src: Union[str, bytes] |
canvas/image.py |
Removed src_bytes, updated src to Optional[Union[str, bytes]] |
box.py |
Removed src_base64 and src_bytes from DecorationImage, updated copy method |
lottie.dart |
Uses ResolvedAssetSource instead of separate base64 handling |
lottie.py |
Removed src_base64, changed default for enable_merge_paths to True |
audio.dart |
Uses ResolvedAssetSource with listEquals for bytes comparison |
audio.py |
Removed src_base64, consolidated into src: Optional[Union[str, bytes]] |
strings.dart |
Added isBase64 and stripBase64DataHeader() extension methods |
| Various test files | Updated to use consolidated src property |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| """ | ||
|
|
||
| src: Optional[str] = None | ||
| src: Union[str, bytes] |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The src property should be Optional[Union[str, bytes]] instead of requiring it, as there may be cases where error_content needs to be shown without a source. Looking at other controls like canvas/image.py which uses Optional[Union[str, bytes]], this should be consistent.
| """ | ||
|
|
||
| src: Optional[str] = None | ||
| src: Union[str, bytes] |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to Image control, the src property should be Optional[Union[str, bytes]] for consistency and to allow for optional rendering with error_content fallback.
| src: Union[str, bytes] | |
| src: Optional[Union[str, bytes]] |
| bool get isBase64 { | ||
| var s = stripBase64DataHeader().replaceAll(RegExp(r'\s+'), ''); | ||
|
|
||
| try { | ||
| final normalized = base64.normalize(s); | ||
| base64.decode(normalized); | ||
| return true; | ||
| } catch (_) { | ||
| return false; | ||
| } | ||
| } |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isBase64 getter performs two operations: normalization and decoding. If this is called frequently, consider caching the result or avoiding the decode step if normalization is sufficient for validation. The decode operation allocates memory that's immediately discarded.
| int arrayIndexOf(Uint8List haystack, Uint8List needle) { | ||
| var len = needle.length; | ||
| var limit = haystack.length - len; | ||
| final len = needle.length; | ||
| if (len == 0) return 0; |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The edge case handling for empty needle returns 0, which could be confusing. Consider documenting why empty needle returns 0 (typically means 'found at start') or consider returning -1 for consistency with 'not found' semantics.
| } else if (resolvedSrc.bytes != null && | ||
| (_srcBytes == null || !listEquals(_srcBytes, resolvedSrc.bytes))) { |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using listEquals for comparing potentially large audio byte arrays on every update could be expensive. Consider using a hash or length check as a quick first pass before doing full byte comparison, or storing a hash of the bytes for efficient comparison.
# Conflicts: # sdk/python/packages/flet/integration_tests/controls/core/test_image.py
Replaced ResolvedAssetSource.from(...get('src')) with getSrc('src') in audio and lottie Dart files for improved asset source resolution. Cleaned up argument formatting and improved readability in lottie.dart. Updated brush.py to use src_bytes instead of src for file saving. Removed unused page argument and debug print statements from image_switch_buffered.py.
* Update Flutter version to 3.38.2 and dependencies Bumped the required Flutter version to 3.38.2 in .fvmrc and build.py. Updated several Dart dependencies in pubspec.lock and removed path_provider_foundation from macOS plugin registration to reflect dependency changes. * Update ci.yml * Update Flutter cache key format in CI workflow Revised the cache-key and pub-cache-key formats in the CI workflow to use placeholders (:os:, :channel:, :version:, :hash:) instead of GitHub Actions variables. This may improve cache management and compatibility with the flutter-fvm-config-action. * Update Flutter cache keys to include architecture Modified cache-key and pub-cache-key in CI and macOS integration workflows to include architecture. This improves cache granularity and prevents issues when running workflows on different architectures. * Disable cache in Flutter FVM setup actions Set 'cache' to false in the flutter-fvm-config-action setup steps for both CI and macOS integration test workflows. This change disables caching to potentially resolve issues related to cache usage or improve workflow reliability. * Add Flutter caching to CI workflows Introduces a cache step for Flutter in both CI and macOS integration test workflows using actions/cache. This improves build performance by reusing Flutter dependencies between runs. * Add step to print Flutter cache outputs in CI Introduces a step in both CI and macOS integration test workflows to print the Flutter cache path and key outputs. This aids in debugging and verifying cache configuration during workflow runs. * Update Flutter setup in CI workflows Replaces kuhnroyal/flutter-fvm-config-action/setup with subosito/flutter-action for Flutter setup in both ci.yml and macos-integration-tests.yml. Adds a separate step to configure Flutter version using .fvmrc and removes printing of Flutter outputs. * Add spacing option to CupertinoCheckbox label Introduces a 'spacing' property to CupertinoCheckbox for customizing the space between the checkbox and its label. Updates Dart and Python implementations, integration tests, and golden images to reflect this change. Also refactors test cases for improved clarity and coverage. Flutter change: flutter/flutter#172502 * Update golden images for macOS material tests Refreshed golden images for submenu button and time picker integration tests on macOS to reflect recent UI or rendering changes. * Improve mouse gesture handling in FlutterWidgetTester Introduces proper mouse pointer exit before tap, long press, and text entry actions to avoid lingering gestures. Updates mouse hover logic to manage gesture lifecycle. Also updates navigation bar test destinations and golden images for macOS time picker and navigation bar. * Update dropdown theme_1.png golden image Replaces the macOS dropdown theme_1.png golden image in integration tests to reflect updated visual output or design changes. * Update golden image for macOS menu bar test Replaces the menu_bar_basic_open.png golden image used in integration tests for the macOS menu bar control. This ensures test accuracy with the latest UI changes. * Remove unnecessary mouse exit calls in FlutterWidgetTester Eliminated redundant _mouseExit() calls before tap, longPress, and enterText actions in FlutterWidgetTester to streamline test interactions. Also updated golden image for navigation bar theme on macOS. * Add 'persist' option to SnackBar control Introduces a 'persist' property to the SnackBar control in Dart and Python, allowing developers to specify whether the snack bar should remain visible after the timeout. Updates documentation and example usage to reflect the new option. Breaking change: https://docs.flutter.dev/release/breaking-changes/snackbar-with-action-behavior-update * Make spacing property optional in CupertinoCheckbox Changed the type of the spacing property from Number to Optional[Number] in CupertinoCheckbox to allow for None values and improve flexibility.
Fix #5470
Example: