From c930989c2efa544e9231af9b6e50da103e8148e5 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Mon, 12 May 2025 06:38:36 +0200 Subject: [PATCH 01/11] Lottie --- client/lib/main.dart | 4 ++-- client/pubspec.yaml | 10 +++++----- packages/flet/lib/src/models/asset_source.dart | 5 +++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/client/lib/main.dart b/client/lib/main.dart index e12897a25..6cd92b2cd 100644 --- a/client/lib/main.dart +++ b/client/lib/main.dart @@ -9,7 +9,7 @@ import 'package:flet_audio/flet_audio.dart' as flet_audio; // as flet_audio_recorder; // import "package:flet_flashlight/flet_flashlight.dart" as flet_flashlight; // import 'package:flet_geolocator/flet_geolocator.dart' as flet_geolocator; -// import 'package:flet_lottie/flet_lottie.dart' as flet_lottie; +import 'package:flet_lottie/flet_lottie.dart' as flet_lottie; // import 'package:flet_map/flet_map.dart' as flet_map; // import 'package:flet_permission_handler/flet_permission_handler.dart' // as flet_permission_handler; @@ -42,7 +42,7 @@ void main([List? args]) async { // flet_audio_recorder.ensureInitialized(); // flet_geolocator.ensureInitialized(); // flet_permission_handler.ensureInitialized(); - // flet_lottie.ensureInitialized(); + extensions.add(flet_lottie.Extension()); // flet_map.ensureInitialized(); // flet_ads.ensureInitialized(); // flet_rive.ensureInitialized(); diff --git a/client/pubspec.yaml b/client/pubspec.yaml index d72f459ef..0f25e7177 100644 --- a/client/pubspec.yaml +++ b/client/pubspec.yaml @@ -44,11 +44,11 @@ dependencies: ref: v1 path: src/flutter/flet_video # --FAT_CLIENT_END-- -# flet_lottie: -# git: -# url: https://github.com/flet-dev/flet-lottie.git -# ref: 0.1.0 -# path: src/flutter/flet_lottie + flet_lottie: + git: + url: https://github.com/flet-dev/flet-lottie.git + ref: v1 + path: src/flutter/flet_lottie # flet_map: # git: # url: https://github.com/flet-dev/flet-map.git diff --git a/packages/flet/lib/src/models/asset_source.dart b/packages/flet/lib/src/models/asset_source.dart index 1134ebe6e..5227d65a1 100644 --- a/packages/flet/lib/src/models/asset_source.dart +++ b/packages/flet/lib/src/models/asset_source.dart @@ -3,4 +3,9 @@ class AssetSource { final bool isFile; const AssetSource({required this.path, required this.isFile}); + + @override + String toString() { + return 'AssetSource(path: $path, isFile: $isFile)'; + } } From 1e57c8604869cdaec93ea596576205e39e279cf9 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Wed, 14 May 2025 16:13:44 +0200 Subject: [PATCH 02/11] create `utils/geometry.dart` with `Rect` and `Size` --- packages/flet/lib/flet.dart | 1 + packages/flet/lib/src/utils/geometry.dart | 40 +++++ packages/flet/lib/src/utils/misc.dart | 16 -- packages/flet/lib/src/utils/theme.dart | 1 + sdk/python/packages/flet/src/flet/__init__.py | 3 +- .../flet/src/flet/controls/geometry.py | 142 ++++++++++++++++++ .../flet/src/flet/controls/padding.py | 4 + .../packages/flet/src/flet/controls/size.py | 68 --------- 8 files changed, 190 insertions(+), 85 deletions(-) create mode 100644 packages/flet/lib/src/utils/geometry.dart create mode 100644 sdk/python/packages/flet/src/flet/controls/geometry.py delete mode 100644 sdk/python/packages/flet/src/flet/controls/size.py diff --git a/packages/flet/lib/flet.dart b/packages/flet/lib/flet.dart index 948aa7d28..b018a7fc0 100644 --- a/packages/flet/lib/flet.dart +++ b/packages/flet/lib/flet.dart @@ -30,6 +30,7 @@ export 'src/utils/drawing.dart'; export 'src/utils/edge_insets.dart'; export 'src/utils/events.dart'; export 'src/utils/form_field.dart'; +export 'src/utils/geometry.dart'; export 'src/utils/gesture_detector.dart'; export 'src/utils/gradient.dart'; export 'src/utils/icons.dart'; diff --git a/packages/flet/lib/src/utils/geometry.dart b/packages/flet/lib/src/utils/geometry.dart new file mode 100644 index 000000000..fc47b6c53 --- /dev/null +++ b/packages/flet/lib/src/utils/geometry.dart @@ -0,0 +1,40 @@ +import 'package:flutter/animation.dart'; + +import '../models/control.dart'; +import 'numbers.dart'; + +Size? parseSize(dynamic value, [Size? defaultValue]) { + if (value == null) return defaultValue; + + final width = parseDouble(value['width']); + final height = parseDouble(value['height']); + + if (width == null || height == null) return defaultValue; + + return Size(width, height); +} + +Rect? parseRect(dynamic value, [Rect? defaultValue]) { + if (value == null) return defaultValue; + + final left = parseDouble(value['left']); + final top = parseDouble(value['top']); + final right = parseDouble(value['right']); + final bottom = parseDouble(value['bottom']); + + if (left == null || top == null || right == null || bottom == null) { + return defaultValue; + } + + return Rect.fromLTRB(left, top, right, bottom); +} + +extension GeometryParsers on Control { + Size? getSize(String propertyName, [Size? defaultValue]) { + return parseSize(get(propertyName), defaultValue); + } + + Rect? getRect(String propertyName, [Rect? defaultValue]) { + return parseRect(get(propertyName), defaultValue); + } +} diff --git a/packages/flet/lib/src/utils/misc.dart b/packages/flet/lib/src/utils/misc.dart index e6a51fc37..e5d71bf7a 100644 --- a/packages/flet/lib/src/utils/misc.dart +++ b/packages/flet/lib/src/utils/misc.dart @@ -5,7 +5,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import '../models/control.dart'; -import 'numbers.dart'; Clip? parseClip(String? value, [Clip? defaultValue]) { if (value == null) return defaultValue; @@ -62,17 +61,6 @@ SliderInteraction? parseSliderInteraction(String? value, defaultValue; } -Size? parseSize(dynamic value, [Size? defaultValue]) { - if (value == null) return defaultValue; - - final width = parseDouble(value['width']); - final height = parseDouble(value['height']); - - if (width == null || height == null) return defaultValue; - - return Size(width, height); -} - SnackBarBehavior? parseSnackBarBehavior(String? value, [SnackBarBehavior? defaultValue]) { if (value == null) return defaultValue; @@ -221,10 +209,6 @@ extension MiscParsers on Control { return parseSliderInteraction(get(propertyName), defaultValue); } - Size? getSize(String propertyName, [Size? defaultValue]) { - return parseSize(get(propertyName), defaultValue); - } - SnackBarBehavior? getSnackBarBehavior(String propertyName, [SnackBarBehavior? defaultValue]) { return parseSnackBarBehavior(get(propertyName), defaultValue); diff --git a/packages/flet/lib/src/utils/theme.dart b/packages/flet/lib/src/utils/theme.dart index 9c2072b37..7a9f39a2e 100644 --- a/packages/flet/lib/src/utils/theme.dart +++ b/packages/flet/lib/src/utils/theme.dart @@ -13,6 +13,7 @@ import 'buttons.dart'; import 'colors.dart'; import 'dismissible.dart'; import 'edge_insets.dart'; +import 'geometry.dart'; import 'icons.dart'; import 'locale.dart'; import 'material_state.dart'; diff --git a/sdk/python/packages/flet/src/flet/__init__.py b/sdk/python/packages/flet/src/flet/__init__.py index ba931a6e0..04ad5ea59 100644 --- a/sdk/python/packages/flet/src/flet/__init__.py +++ b/sdk/python/packages/flet/src/flet/__init__.py @@ -402,7 +402,7 @@ from flet.controls.services.service import Service from flet.controls.services.shake_detector import ShakeDetector from flet.controls.services.storage_paths import StoragePaths -from flet.controls.size import Size +from flet.controls.geometry import Size, Rect from flet.controls.template_route import TemplateRoute from flet.controls.text_style import ( OptionalStrutStyle, @@ -886,6 +886,7 @@ "ShakeDetector", "StoragePaths", "Size", + "Rect", "TemplateRoute", "OptionalStrutStyle", "OptionalTextBaseline", diff --git a/sdk/python/packages/flet/src/flet/controls/geometry.py b/sdk/python/packages/flet/src/flet/controls/geometry.py new file mode 100644 index 000000000..1da094c39 --- /dev/null +++ b/sdk/python/packages/flet/src/flet/controls/geometry.py @@ -0,0 +1,142 @@ +from dataclasses import dataclass + +from flet.controls.transform import Offset +from flet.controls.types import Number + +__all__ = [ + "Size", + "Rect", +] + + +@dataclass +class Size: + """ + A 2D size with width and height. + """ + + width: Number + height: Number + + @property + def aspect_ratio(self) -> float: + """Returns the aspect ratio (width / height).""" + if self.height != 0.0: + return self.width / self.height + if self.width > 0.0: + return float("inf") + if self.width < 0.0: + return float("-inf") + return 0.0 + + def is_infinite(self) -> bool: + """Checks if either dimension is infinite.""" + return self.width == float("inf") or self.height == float("inf") + + def is_finite(self) -> bool: + """Checks if both dimensions are finite.""" + return self.width != float("inf") and self.height != float("inf") + + @classmethod + def copy(cls, source: "Size") -> "Size": + """Creates a copy of the given Size object.""" + return Size(source.width, source.height) + + @classmethod + def square(cls, dimension: Number) -> "Size": + """Creates a square Size where width and height are the same.""" + return Size(dimension, dimension) + + @classmethod + def from_width(cls, width: Number) -> "Size": + """Creates a Size with the given width and an infinite height.""" + return Size(width, float("inf")) + + @classmethod + def from_height(cls, height: Number) -> "Size": + """Creates a Size with the given height and an infinite width.""" + return Size(float("inf"), height) + + @classmethod + def from_radius(cls, radius: Number) -> "Size": + """Creates a square Size whose width and height are twice the given radius.""" + return Size(radius * 2.0, radius * 2.0) + + @classmethod + def zero(cls): + return Size(0.0, 0.0) + + @classmethod + def infinite(cls): + return Size(float("inf"), float("inf")) + + +@dataclass +class Rect: + """ + A 2D, axis-aligned, floating-point rectangle whose coordinates are relative to a given origin. + """ + + left: Number + """The offset of the left edge of this rectangle from the x-axis.""" + + top: Number + """The offset of the top edge of this rectangle from the y-axis.""" + + right: Number + """The offset of the right edge of this rectangle from the x-axis.""" + + bottom: Number + """The offset of the bottom edge of this rectangle from the y-axis.""" + + @property + def width(self) -> Number: + """The distance between the left and right edges of this rectangle.""" + return self.right - self.left + + @property + def height(self) -> Number: + """The distance between the top and bottom edges of this rectangle.""" + return self.bottom - self.top + + @property + def size(self) -> Size: + """ + The distance between the upper-left corner + and the lower-right corner of this rectangle. + """ + return Size(self.width, self.height) + + @classmethod + def from_lwth(cls, *, left: Number, top: Number, width: Number, height: Number) -> "Rect": + """ + Construct a rectangle from its left and top edges, + its width, and its height. + """ + return Rect(left, top, left + width, top + height) + + @classmethod + def from_center(cls, *, center: Offset, width: Number, height: Number): + """ + Constructs a rectangle from its center point, width, and height. + The `center` argument is assumed to be an offset from the origin. + """ + return Rect( + center.x - width / 2, + center.y - height / 2, + center.x + width / 2, + center.y + height / 2, + ) + + @classmethod + def from_points(cls, a: Offset, b: Offset): + """ + Construct the smallest rectangle that encloses the given offsets, + treating them as vectors from the origin. + """ + return Rect( + min(a.x, b.x), + min(a.y, b.y), + max(a.x, b.x), + max(a.y, b.y), + ) \ No newline at end of file diff --git a/sdk/python/packages/flet/src/flet/controls/padding.py b/sdk/python/packages/flet/src/flet/controls/padding.py index 461755a53..17bd0c7da 100644 --- a/sdk/python/packages/flet/src/flet/controls/padding.py +++ b/sdk/python/packages/flet/src/flet/controls/padding.py @@ -35,6 +35,10 @@ def only( ) -> "Padding": return Padding(left=left, top=top, right=right, bottom=bottom) + @classmethod + def zero(cls) -> "Padding": + return Padding.only() + @deprecated( reason="Use Padding.all() instead", diff --git a/sdk/python/packages/flet/src/flet/controls/size.py b/sdk/python/packages/flet/src/flet/controls/size.py deleted file mode 100644 index d0deeafde..000000000 --- a/sdk/python/packages/flet/src/flet/controls/size.py +++ /dev/null @@ -1,68 +0,0 @@ -from dataclasses import dataclass - -from flet.controls.types import Number - -__all__ = [ - "Size", - "zero", - "infinite", -] - - -@dataclass(frozen=True) -class Size: - """ - A class representing a 2D size with width and height. - """ - - width: float - height: float - - @property - def aspect_ratio(self) -> float: - """Returns the aspect ratio (width / height).""" - if self.height != 0.0: - return self.width / self.height - if self.width > 0.0: - return float("inf") - if self.width < 0.0: - return float("-inf") - return 0.0 - - def is_infinite(self) -> bool: - """Checks if either dimension is infinite.""" - return self.width == float("inf") or self.height == float("inf") - - def is_finite(self) -> bool: - """Checks if both dimensions are finite.""" - return self.width != float("inf") and self.height != float("inf") - - @classmethod - def copy(cls, source: "Size") -> "Size": - """Creates a copy of the given Size object.""" - return Size(source.width, source.height) - - @classmethod - def square(cls, dimension: Number) -> "Size": - """Creates a square Size where width and height are the same.""" - return Size(dimension, dimension) - - @classmethod - def from_width(cls, width: Number) -> "Size": - """Creates a Size with the given width and an infinite height.""" - return Size(width, float("inf")) - - @classmethod - def from_height(cls, height: Number) -> "Size": - """Creates a Size with the given height and an infinite width.""" - return Size(float("inf"), height) - - @classmethod - def from_radius(cls, radius: Number) -> "Size": - """Creates a square Size whose width and height are twice the given radius.""" - return Size(radius * 2.0, radius * 2.0) - - -# Constants -zero = Size(0.0, 0.0) -infinite = Size(float("inf"), float("inf")) From 4f3a666601310ac3ab6a183dde3854847c20ea3f Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Wed, 14 May 2025 16:15:22 +0200 Subject: [PATCH 03/11] add flet-rive to client --- client/lib/main.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/lib/main.dart b/client/lib/main.dart index 6cd92b2cd..dd31a7a76 100644 --- a/client/lib/main.dart +++ b/client/lib/main.dart @@ -13,7 +13,7 @@ import 'package:flet_lottie/flet_lottie.dart' as flet_lottie; // import 'package:flet_map/flet_map.dart' as flet_map; // import 'package:flet_permission_handler/flet_permission_handler.dart' // as flet_permission_handler; -// import 'package:flet_rive/flet_rive.dart' as flet_rive; +import 'package:flet_rive/flet_rive.dart' as flet_rive; // --FAT_CLIENT_START-- import 'package:flet_video/flet_video.dart' as flet_video; // --FAT_CLIENT_END-- @@ -45,7 +45,7 @@ void main([List? args]) async { extensions.add(flet_lottie.Extension()); // flet_map.ensureInitialized(); // flet_ads.ensureInitialized(); - // flet_rive.ensureInitialized(); + extensions.add(flet_rive.Extension()); // flet_webview.ensureInitialized(); // flet_flashlight.ensureInitialized(); From fa0d961ecfcfaafe994f0e51989f37c75c3709e2 Mon Sep 17 00:00:00 2001 From: TheEthicalBoy <98978078+ndonkoHenri@users.noreply.github.com> Date: Tue, 27 May 2025 03:30:35 +0200 Subject: [PATCH 04/11] uncomment flet-rive in pubspec.yaml --- client/pubspec.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/pubspec.yaml b/client/pubspec.yaml index 0f25e7177..2143847b4 100644 --- a/client/pubspec.yaml +++ b/client/pubspec.yaml @@ -60,11 +60,11 @@ dependencies: # ref: 0.1.0 # path: src/flutter/flet_ads -# flet_rive: -# git: -# url: https://github.com/flet-dev/flet-rive.git -# ref: 0.1.0 -# path: src/flutter/flet_rive + flet_rive: + git: + url: https://github.com/flet-dev/flet-rive.git + ref: v1 + path: src/flutter/flet_rive # flet_audio_recorder: # git: From 103d992c1dcfd4a62f241436d3656859a91d9229 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Tue, 27 May 2025 03:36:08 +0200 Subject: [PATCH 05/11] fix missing colors --- sdk/python/packages/flet/src/flet/controls/colors.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdk/python/packages/flet/src/flet/controls/colors.py b/sdk/python/packages/flet/src/flet/controls/colors.py index 57b502c47..c79cad58e 100644 --- a/sdk/python/packages/flet/src/flet/controls/colors.py +++ b/sdk/python/packages/flet/src/flet/controls/colors.py @@ -100,7 +100,10 @@ def random( ON_ERROR_CONTAINER = "onerrorcontainer" OUTLINE = "outline" OUTLINE_VARIANT = "outlinevariant" + SURFACE = "surface" + ON_SURFACE = "onsurface" SURFACE_TINT = "surfacetint" + SURFACE_CONTAINER_HIGHEST = "surfaceContainerHighest" ON_SURFACE_VARIANT = "onsurfacevariant" INVERSE_SURFACE = "inversesurface" ON_INVERSE_SURFACE = "oninversesurface" From f6f23ce9424b051c25e57591b6dde84ea7c9d424 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Tue, 27 May 2025 03:36:41 +0200 Subject: [PATCH 06/11] fix imports --- sdk/python/packages/flet/src/flet/controls/theme.py | 2 +- sdk/python/packages/flet/src/flet/controls/transform.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/sdk/python/packages/flet/src/flet/controls/theme.py b/sdk/python/packages/flet/src/flet/controls/theme.py index 0a0f87e18..e804ecc6c 100644 --- a/sdk/python/packages/flet/src/flet/controls/theme.py +++ b/sdk/python/packages/flet/src/flet/controls/theme.py @@ -19,7 +19,7 @@ from flet.controls.material.textfield import TextCapitalization from flet.controls.material.tooltip import TooltipTriggerMode from flet.controls.padding import OptionalPaddingValue, PaddingValue -from flet.controls.size import Size +from flet.controls.geometry import Size from flet.controls.text_style import OptionalTextStyle, TextStyle from flet.controls.transform import OffsetValue from flet.controls.types import ( diff --git a/sdk/python/packages/flet/src/flet/controls/transform.py b/sdk/python/packages/flet/src/flet/controls/transform.py index 9e01d4492..f131e6daf 100644 --- a/sdk/python/packages/flet/src/flet/controls/transform.py +++ b/sdk/python/packages/flet/src/flet/controls/transform.py @@ -36,6 +36,10 @@ class Offset: x: Number y: Number + @classmethod + def zero(cls): + return Offset(0, 0) + # typing RotateValue = Union[Number, Rotate] From be4df8b41c9160c99a878706bff22434433a6163 Mon Sep 17 00:00:00 2001 From: TheEthicalBoy <98978078+ndonkoHenri@users.noreply.github.com> Date: Tue, 27 May 2025 05:14:15 +0200 Subject: [PATCH 07/11] add flet-map pubspec.yaml --- client/pubspec.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/client/pubspec.yaml b/client/pubspec.yaml index 2143847b4..916564763 100644 --- a/client/pubspec.yaml +++ b/client/pubspec.yaml @@ -49,11 +49,11 @@ dependencies: url: https://github.com/flet-dev/flet-lottie.git ref: v1 path: src/flutter/flet_lottie -# flet_map: -# git: -# url: https://github.com/flet-dev/flet-map.git -# ref: 0.1.0 -# path: src/flutter/flet_map + flet_map: + git: + url: https://github.com/flet-dev/flet-map.git + ref: v1 + path: src/flutter/flet_map # flet_ads: # git: # url: https://github.com/flet-dev/flet-ads.git From 545774ce4b22cbfb4a4ca812c3b9d74988e50900 Mon Sep 17 00:00:00 2001 From: TheEthicalBoy <98978078+ndonkoHenri@users.noreply.github.com> Date: Tue, 27 May 2025 05:14:33 +0200 Subject: [PATCH 08/11] add flet-map to main.dart --- client/lib/main.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/lib/main.dart b/client/lib/main.dart index dd31a7a76..be7d2dda9 100644 --- a/client/lib/main.dart +++ b/client/lib/main.dart @@ -10,7 +10,7 @@ import 'package:flet_audio/flet_audio.dart' as flet_audio; // import "package:flet_flashlight/flet_flashlight.dart" as flet_flashlight; // import 'package:flet_geolocator/flet_geolocator.dart' as flet_geolocator; import 'package:flet_lottie/flet_lottie.dart' as flet_lottie; -// import 'package:flet_map/flet_map.dart' as flet_map; +import 'package:flet_map/flet_map.dart' as flet_map; // import 'package:flet_permission_handler/flet_permission_handler.dart' // as flet_permission_handler; import 'package:flet_rive/flet_rive.dart' as flet_rive; @@ -43,7 +43,7 @@ void main([List? args]) async { // flet_geolocator.ensureInitialized(); // flet_permission_handler.ensureInitialized(); extensions.add(flet_lottie.Extension()); - // flet_map.ensureInitialized(); + extensions.add(flet_map.Extension()); // flet_ads.ensureInitialized(); extensions.add(flet_rive.Extension()); // flet_webview.ensureInitialized(); From 74cf4ea53e2eca6dcdca4e70655579ae7c3c5dab Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Tue, 27 May 2025 19:03:40 +0200 Subject: [PATCH 09/11] add flet-webview to client --- client/lib/main.dart | 14 +++++++------- client/pubspec.yaml | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/client/lib/main.dart b/client/lib/main.dart index be7d2dda9..15dc401f1 100644 --- a/client/lib/main.dart +++ b/client/lib/main.dart @@ -17,7 +17,7 @@ import 'package:flet_rive/flet_rive.dart' as flet_rive; // --FAT_CLIENT_START-- import 'package:flet_video/flet_video.dart' as flet_video; // --FAT_CLIENT_END-- -// import 'package:flet_webview/flet_webview.dart' as flet_webview; +import 'package:flet_webview/flet_webview.dart' as flet_webview; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_web_plugins/url_strategy.dart'; @@ -39,15 +39,15 @@ void main([List? args]) async { extensions.add(flet_audio.Extension()); extensions.add(flet_video.Extension()); // --FAT_CLIENT_END-- - // flet_audio_recorder.ensureInitialized(); - // flet_geolocator.ensureInitialized(); - // flet_permission_handler.ensureInitialized(); + // extensions.add(flet_audio_recorder.Extension()); + // extensions.add(flet_geolocator.Extension()); + // extensions.add(flet_permission_handler.Extension()); extensions.add(flet_lottie.Extension()); extensions.add(flet_map.Extension()); - // flet_ads.ensureInitialized(); + // extensions.add(flet_ads.Extension()); extensions.add(flet_rive.Extension()); - // flet_webview.ensureInitialized(); - // flet_flashlight.ensureInitialized(); + extensions.add(flet_webview.Extension()); + // extensions.add(flet_flashlight.Extension()); // initialize extensions for (var extension in extensions) { diff --git a/client/pubspec.yaml b/client/pubspec.yaml index 916564763..e7bf5b30a 100644 --- a/client/pubspec.yaml +++ b/client/pubspec.yaml @@ -84,11 +84,11 @@ dependencies: # ref: 0.1.0 # path: src/flutter/flet_geolocator -# flet_webview: -# git: -# url: https://github.com/flet-dev/flet-webview.git -# ref: 0.1.0 -# path: src/flutter/flet_webview + flet_webview: + git: + url: https://github.com/flet-dev/flet-webview.git + ref: v1 + path: src/flutter/flet_webview # flet_flashlight: # git: # url: https://github.com/flet-dev/flet-flashlight.git From 63ac60551cf08fa16f5ef4b1c52ef5f2c9cdef78 Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Wed, 28 May 2025 02:07:48 +0200 Subject: [PATCH 10/11] more docs --- .../flet/src/flet/controls/base_control.py | 11 +++ .../src/flet/controls/constrained_control.py | 76 +++++++++++++++++++ .../flet/src/flet/controls/control.py | 31 ++++++++ .../packages/flet/src/flet/controls/ref.py | 2 + 4 files changed, 120 insertions(+) diff --git a/sdk/python/packages/flet/src/flet/controls/base_control.py b/sdk/python/packages/flet/src/flet/controls/base_control.py index e6cd4fa41..9b8f66cdd 100644 --- a/sdk/python/packages/flet/src/flet/controls/base_control.py +++ b/sdk/python/packages/flet/src/flet/controls/base_control.py @@ -98,7 +98,10 @@ class BaseControl: _i: int = field(init=False) _c: str = field(init=False) data: Any = skip_field() + """Arbitrary data of any type that can be attached to a control.""" + ref: InitVar[Optional[Ref["BaseControl"]]] = None + """A reference to this control.""" def __post_init__(self, ref: Optional[Ref[Any]]): self.__class__.__hash__ = BaseControl.__hash__ @@ -121,11 +124,19 @@ def __hash__(self) -> int: @property def parent(self) -> Optional["BaseControl"]: + """ + The direct ancestor(parent) of this control. + + It defaults to `None` and will only have a value when this control is mounted (added to the page tree). + + The `Page` control (which is the root of the tree) is an exception - it always has parent=None. + """ parent_ref = getattr(self, "_parent", None) return parent_ref() if parent_ref else None @property def page(self) -> Optional[Union["Page", "PageView"]]: + """The page (of type `Page` or `PageView`) this control belongs to.""" from .page import Page, PageView parent = self.parent diff --git a/sdk/python/packages/flet/src/flet/controls/constrained_control.py b/sdk/python/packages/flet/src/flet/controls/constrained_control.py index dcebd42c8..5dc46919f 100644 --- a/sdk/python/packages/flet/src/flet/controls/constrained_control.py +++ b/sdk/python/packages/flet/src/flet/controls/constrained_control.py @@ -12,20 +12,96 @@ @control(kw_only=True) class ConstrainedControl(Control): scroll_key: Optional[str] = None + """""" + width: OptionalNumber = None + """Imposed Control width in virtual pixels.""" + height: OptionalNumber = None + """Imposed Control height in virtual pixels.""" + left: OptionalNumber = None + """ + The distance that the child's left edge is inset from the left of it's parent. + Effective inside the following only: `Stack`, `Page.overlay` + """ + top: OptionalNumber = None + """ + The distance that the child's top edge is inset from the top of it's parent. + Effective inside the following only: `Stack`, `Page.overlay` + """ + right: OptionalNumber = None + """ + The distance that the child's right edge is inset from the right of it's parent. + Effective inside the following only: `Stack`, `Page.overlay` + """ + bottom: OptionalNumber = None + """ + The distance that the child's bottom edge is inset from the bottom of it's parent. + Effective inside the following only: `Stack`, `Page.overlay` + """ + rotate: Optional[RotateValue] = None + """ + Applies a rotation transform to the control around its center. + + The `rotate` value can be: + - A number: Specifies the rotation in clockwise radians. For reference: + • Full circle (360°) = `2 * math.pi` + • 90° = `math.pi / 2` + • 45° = `math.pi / 4` + - A `Rotate` object: Allows specifying both the rotation angle + and the alignment (i.e., the pivot point for rotation). + """ + scale: Optional[ScaleValue] = None + """ + Scale control along the 2D plane. + + The value of this property can be a number or an instance of `Scale` class. + + Default scale factor is `1.0` - control is not scaled. + `0.5` - the control is twice smaller, `2.0` - the control is twice larger. + """ + offset: Optional[OffsetValue] = None + """ + Applies a translation transform to the control before it is painted. + + The translation is specified as an `Offset`, where each component is scaled relative to the control's size. + For example, an `Offset(x=0.25, y=0)` translates the control horizontally by 25% of its width. + + Example: + If the control is placed at (0, 0) in a `Stack` and has a size of 100x100, an `offset` of (-1, -1) moves the control + left and up by 100 pixels, effectively positioning it at (-100, -100). + """ + aspect_ratio: OptionalNumber = None + """ + The aspect ratio of the control. + """ + animate_opacity: Optional[AnimationValue] = None + """""" + animate_size: Optional[AnimationValue] = None + """""" + animate_position: Optional[AnimationValue] = None + """""" + animate_rotation: Optional[AnimationValue] = None + """""" + animate_scale: Optional[AnimationValue] = None + """""" + animate_offset: Optional[AnimationValue] = None + """""" + on_animation_end: OptionalControlEventCallable = None + """""" + diff --git a/sdk/python/packages/flet/src/flet/controls/control.py b/sdk/python/packages/flet/src/flet/controls/control.py index 32c210fbb..0f9e389bb 100644 --- a/sdk/python/packages/flet/src/flet/controls/control.py +++ b/sdk/python/packages/flet/src/flet/controls/control.py @@ -18,10 +18,41 @@ class Control(BaseControl): expand_loose: Optional[bool] = None col: ResponsiveNumber = 12 # todo: if dict, validate keys with those in parent (ResponsiveRow.breakpoints) opacity: Number = 1.0 + """ + Defines the transparency of the control. + It's ranges from `0.0` (completely transparent) to + `1.0` (completely opaque without any transparency). + + Defaults to `1.0´. + """ tooltip: Optional[TooltipValue] = None + """ + A tooltip message to show when the user hovers over the control. + + The tooltip can be of type `str` or `Tooltip`. + """ + badge: Optional[BadgeValue] = None + """ + A badge to show on top of the control. + + The badge can be of type `str` or `Badge`. + """ + visible: bool = True + """ + Whether the control is visible or not. + + Defaults to `True`. + """ + disabled: bool = False + """ + Whether the control is disabled or not. + + Defaults to `False`. + """ + rtl: bool = False def before_update(self): diff --git a/sdk/python/packages/flet/src/flet/controls/ref.py b/sdk/python/packages/flet/src/flet/controls/ref.py index 2ccea5f35..3ed7dea7e 100644 --- a/sdk/python/packages/flet/src/flet/controls/ref.py +++ b/sdk/python/packages/flet/src/flet/controls/ref.py @@ -6,6 +6,8 @@ class Ref(Generic[T]): + """Utility class which allows defining a reference to a control.""" + def __init__(self): self._current: Optional[weakref.ref[T]] = None From a610d4df6e4c970646890dba56b1199045a2996d Mon Sep 17 00:00:00 2001 From: ndonkoHenri Date: Thu, 29 May 2025 01:30:50 +0200 Subject: [PATCH 11/11] remove Duration.from_datetime --- .../packages/flet/src/flet/controls/duration.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/sdk/python/packages/flet/src/flet/controls/duration.py b/sdk/python/packages/flet/src/flet/controls/duration.py index 2f2da8404..6bdbf130a 100644 --- a/sdk/python/packages/flet/src/flet/controls/duration.py +++ b/sdk/python/packages/flet/src/flet/controls/duration.py @@ -64,17 +64,6 @@ def from_unit( days=d, hours=h, minutes=m, seconds=s, milliseconds=ms, microseconds=us ) - @classmethod - def from_datetime(cls, dt: datetime) -> "Duration": - """Creates a Duration from a datetime object.""" - return cls.from_unit( - days=dt.day, - hours=dt.hour, - minutes=dt.minute, - seconds=dt.second, - milliseconds=dt.microsecond // MICROSECONDS_PER_MILLISECOND, - ) - # Properties @property