Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/flet/lib/src/utils/drawing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ List<double>? parsePaintStrokeDashPattern(dynamic value,
[List<double>? defaultValue]) {
if (value == null) return defaultValue;

return value["stroke_dash_pattern"] != null
? (value["stroke_dash_pattern"] as List)
.map((e) => parseDouble(e))
return (value["stroke_dash_pattern"] as List?)
?.map((e) => parseDouble(e))
.nonNulls
.toList()
: null;
.toList() ??
defaultValue;
}

ui.Gradient? parsePaintGradient(Map<dynamic, dynamic>? value, ThemeData? theme,
Expand Down
3 changes: 2 additions & 1 deletion sdk/python/packages/flet-ads/src/flet_ads/banner_ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class BannerAd(BaseAd):
Displays a banner ad.

Raises:
AssertionError: When this control is used on a web and/or non-mobile platform.
FletUnsupportedPlatformException: When this control is used on a web
and/or non-mobile platform.
"""

on_will_dismiss: Optional[ft.ControlEventHandler["BannerAd"]] = None
Expand Down
11 changes: 7 additions & 4 deletions sdk/python/packages/flet-ads/src/flet_ads/base_ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class BaseAd(ft.Control):
Base class for all ad controls in Flet Ads package.

Raises:
AssertionError: When using this control on a web and/or non-mobile platform.
FletUnsupportedPlatformException: When using this control on a web
and/or non-mobile platform.
"""

unit_id: str
Expand Down Expand Up @@ -63,6 +64,8 @@ class BaseAd(ft.Control):
"""

def before_update(self):
assert not self.page.web and self.page.platform.is_mobile(), (
f"{self.__class__.__name__} is only supported on Mobile (Android and iOS)"
)
if self.page.web or not self.page.platform.is_mobile():
raise ft.FletUnsupportedPlatformException(
f"{self.__class__.__name__} is only supported on "
f"Mobile (Android and iOS)"
)
3 changes: 2 additions & 1 deletion sdk/python/packages/flet-ads/src/flet_ads/interstitial_ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class InterstitialAd(BaseAd):
Displays a full-screen interstitial ad.

Raises:
AssertionError: When using this control on a web and/or non-mobile platform.
FletUnsupportedPlatformException: When using this control on a
web and/or non-mobile platform.
"""

async def show(self):
Expand Down
15 changes: 8 additions & 7 deletions sdk/python/packages/flet-ads/src/flet_ads/native_ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@
class NativeAd(BannerAd):
"""
Renders a native ad.

Raises:
AssertionError: When neither [`factory_id`][(c).] nor
[`template_style`][(c).] is set.
"""

factory_id: str = None
"""
An identifier for the factory that creates the Platform view.

Raises:
ValueError: When neither `factory_id` nor [`template_style`][(c).] is set.
"""

template_style: NativeAdTemplateStyle = None
"""
A style for the native ad template.

Raises:
ValueError: When neither [`factory_id`][(c).] nor `template_style` is set.
"""

def before_update(self):
super().before_update()
assert self.factory_id is not None or self.template_style is not None, (
"factory_id or template_style must be set"
)
if self.factory_id is None and self.template_style is None:
raise ValueError("factory_id or template_style must be set")
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ async def start_recording(

Returns:
`True` if recording was successfully started, `False` otherwise.

Raises:
ValueError: If `output_path` is not provided on platforms other than web.
"""
assert self.page.web or output_path, (
"output_path must be provided on platforms other than web"
)
if not (self.page.web or output_path):
raise ValueError("output_path must be provided on platforms other than web")
return await self._invoke_method(
method_name="start_recording",
arguments={
Expand Down
7 changes: 4 additions & 3 deletions sdk/python/packages/flet-audio/src/flet_audio/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Audio(ft.Service):
is a list of supported audio formats.

Raises:
AssertionError: If both [`src`][(c).] and [`src_base64`][(c).] are `None`.
ValueError: If both `src` and [`src_base64`][(c).] are `None`.
"""

src_base64: Optional[str] = None
Expand All @@ -41,7 +41,7 @@ class Audio(ft.Service):
is a list of supported audio formats.

Raises:
AssertionError: If both [`src`][(c).] and [`src_base64`][(c).] are `None`.
ValueError: If both `src_base64` and [`src`][(c).] are `None`.
"""

autoplay: bool = False
Expand Down Expand Up @@ -118,7 +118,8 @@ class Audio(ft.Service):

def before_update(self):
super().before_update()
assert self.src or self.src_base64, "either src or src_base64 must be provided"
if not (self.src or self.src_base64):
raise ValueError("either src or src_base64 must be provided")

async def play(self, position: ft.DurationValue = 0):
"""
Expand Down
6 changes: 3 additions & 3 deletions sdk/python/packages/flet-charts/src/flet_charts/bar_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ class BarChart(ft.LayoutControl):

group_spacing: ft.Number = 16.0
"""
A amount of space between bar [`groups`][..].
An amount of space between bar [`groups`][(c).].
"""

group_alignment: ft.MainAxisAlignment = ft.MainAxisAlignment.SPACE_EVENLY
"""
The alignment of the bar [`groups`][..] within this chart.
The alignment of the bar [`groups`][(c).] within this chart.

If set to [`MainAxisAlignment.CENTER`][flet.MainAxisAlignment.CENTER],
the space between the `groups` can be specified using [`group_spacing`][..].
the space between the `groups` can be specified using [`group_spacing`][(c).].
"""

animation: ft.AnimationValue = field(
Expand Down
6 changes: 3 additions & 3 deletions sdk/python/packages/flet-charts/src/flet_charts/chart_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ChartAxisLabel(ft.BaseControl):

label: Optional[ft.StrOrControl] = None
"""
The label to display for the specified [`value`][..].
The label to display for the specified [`value`][(c).].
"""


Expand All @@ -41,7 +41,7 @@ class ChartAxis(ft.BaseControl):

show_labels: bool = True
"""
Whether to display the [`labels`][..] along the axis.
Whether to display the [`labels`][(c).] along the axis.
If `labels` is empty then automatic labels are displayed.
"""

Expand All @@ -61,7 +61,7 @@ class ChartAxis(ft.BaseControl):

label_size: ft.Number = 22
"""
The maximum space for each label in [`labels`][..].
The maximum space for each label in [`labels`][(c).].

Each label will stretch to fit this space.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class LineChartData(ft.BaseControl):

prevent_curve_over_shooting_threshold: ft.Number = 10.0
"""
Threshold for [`prevent_curve_over_shooting`][..] algorithm.
Threshold for [`prevent_curve_over_shooting`][(c).] algorithm.
"""

dash_pattern: Optional[list[int]] = None
Expand Down Expand Up @@ -131,7 +131,7 @@ class LineChartData(ft.BaseControl):
curve_smoothness: ft.Number = 0.35
"""
Defines the smoothness of a curve line,
when [`curved`][..] is set to `True`.
when [`curved`][(c).] is set to `True`.
"""

rounded_stroke_join: bool = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class LineChartDataPoint(ft.BaseControl):

show_tooltip: bool = True
"""
Whether the [`tooltip`][..] should be shown when this data point is hovered over.
Whether the [`tooltip`][(c).] should be shown when this data point is hovered over.
"""

def before_update(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
class PieChartSection(ft.BaseControl):
"""
Configures a [PieChart][(p).] section.

Raises:
AssertionError: If [`title_position`][(c).] or
[`badge_position`][(c).] is not between `0.0` and `1.0` inclusive.
"""

value: ft.Number
Expand Down Expand Up @@ -51,11 +47,13 @@ class PieChartSection(ft.BaseControl):
"""
The position/offset of the title relative to the section's center.

- `0.0`: near the center
- `1.0`: near the outside of the chart

By default the title is drawn in the middle of the section.

Note:
Must be between `0.0` (near the center)
and `1.0`(near the outside of the chart) inclusive.
Raises:
ValueError: If it is not between `0.0` and `1.0` inclusive.
"""

badge: Optional[ft.Control] = None
Expand All @@ -67,11 +65,13 @@ class PieChartSection(ft.BaseControl):
"""
The position/offset of the badge relative to the section's center.

- `0.0`: near the center
- `1.0`: near the outside of the chart

By default the badge is drawn in the middle of the section.

Note:
Must be between `0.0` (near the center)
and `1.0`(near the outside of the chart) inclusive.
Raises:
ValueError: If it is not between `0.0` and `1.0` inclusive.
"""

gradient: Optional[ft.Gradient] = None
Expand All @@ -81,11 +81,13 @@ class PieChartSection(ft.BaseControl):

def before_update(self):
super().before_update()
assert self.title_position is None or (0.0 <= self.title_position <= 1.0), (
f"title_position must be between 0.0 and 1.0 inclusive, "
f"got {self.title_position}"
)
assert self.badge_position is None or (0.0 <= self.badge_position <= 1.0), (
f"badge_position must be between 0.0 and 1.0 inclusive, "
f"got {self.badge_position}"
)
if self.title_position is not None and not (0.0 <= self.title_position <= 1.0):
raise ValueError(
"title_position must be between 0.0 and 1.0 inclusive, "
f"got {self.title_position}"
)
if self.badge_position is not None and not (0.0 <= self.badge_position <= 1.0):
raise ValueError(
"badge_position must be between 0.0 and 1.0 inclusive, "
f"got {self.badge_position}"
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DataColumn2(ft.DataColumn):
fixed_width: Optional[ft.Number] = None
"""
Defines absolute width of the column in pixels
(as opposed to relative [`size`][..] used by default).
(as opposed to relative [`size`][(c).] used by default).
"""

size: Optional[DataColumnSize] = DataColumnSize.S
Expand Down
12 changes: 6 additions & 6 deletions sdk/python/packages/flet-desktop/src/flet_desktop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import zipfile
from pathlib import Path

import flet_desktop
import flet_desktop.version
from flet.utils import (
get_arch,
is_linux,
Expand All @@ -19,9 +21,6 @@
safe_tar_extractall,
)

import flet_desktop
import flet_desktop.version

logger = logging.getLogger(flet_desktop.__name__)


Expand Down Expand Up @@ -146,9 +145,10 @@ def __locate_and_unpack_flet_view(page_url, assets_dir, hidden):
for f in os.listdir(temp_flet_dir):
if f.endswith(".app"):
app_name = f
assert app_name is not None, (
f"Application bundle not found in {temp_flet_dir}"
)
if app_name is None:
raise FileNotFoundError(
f"Application bundle not found in {temp_flet_dir}"
)
app_path = temp_flet_dir.joinpath(app_name)
logger.info(f"page_url: {page_url}")
logger.info(f"pid_file: {pid_file}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ async def get_current_position(
Note:
Depending on the availability of different location services,
this can take several seconds. It is recommended to call the
[`get_last_known_position`][..] method first to receive a
[`get_last_known_position`][(c).] method first to receive a
known/cached position and update it with the result of the
[`get_current_position`][..] method.
[`get_current_position`][(c).] method.

Args:
configuration: Additional configuration for the location request.
Expand Down Expand Up @@ -86,9 +86,12 @@ async def get_last_known_position(self) -> GeolocatorPosition:
The last known position of the device as a [`GeolocatorPosition`][(p).].

Raises:
AssertionError: If invoked on a web platform.
FletUnsupportedPlatformException: If invoked on a web platform.
"""
assert not self.page.web, "get_last_known_position is not supported on web"
if self.page.web:
raise ft.FletUnsupportedPlatformException(
"get_last_known_position is not supported on web"
)
r = await self._invoke_method(
"get_last_known_position",
)
Expand Down Expand Up @@ -138,9 +141,12 @@ async def open_app_settings(self) -> bool:
`True` if the app's settings were opened successfully, `False` otherwise.

Raises:
AssertionError: If invoked on a web platform.
FletUnsupportedPlatformException: If invoked on a web platform.
"""
assert not self.page.web, "open_app_settings is not supported on web"
if self.page.web:
raise ft.FletUnsupportedPlatformException(
"open_app_settings is not supported on web"
)
return await self._invoke_method(
"open_app_settings",
)
Expand All @@ -156,9 +162,12 @@ async def open_location_settings(self) -> bool:
`True` if the device's settings were opened successfully, `False` otherwise.

Raises:
AssertionError: If invoked on a web platform.
FletUnsupportedPlatformException: If invoked on a web platform.
"""
assert not self.page.web, "open_location_settings is not supported on web"
if self.page.web:
raise ft.FletUnsupportedPlatformException(
"open_location_settings is not supported on web"
)
return await self._invoke_method(
"open_location_settings",
)
Expand Down
Loading
Loading