flet 0.70.0.dev5774__py3-none-any.whl → 0.70.0.dev5835__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of flet might be problematic. Click here for more details.

Files changed (96) hide show
  1. flet/__init__.py +32 -4
  2. flet/components/__init__.py +0 -0
  3. flet/components/component.py +346 -0
  4. flet/components/component_decorator.py +24 -0
  5. flet/components/component_owned.py +22 -0
  6. flet/components/hooks/__init__.py +0 -0
  7. flet/components/hooks/hook.py +12 -0
  8. flet/components/hooks/use_callback.py +28 -0
  9. flet/components/hooks/use_context.py +91 -0
  10. flet/components/hooks/use_effect.py +104 -0
  11. flet/components/hooks/use_memo.py +52 -0
  12. flet/components/hooks/use_state.py +58 -0
  13. flet/components/memo.py +34 -0
  14. flet/components/observable.py +269 -0
  15. flet/components/public_utils.py +10 -0
  16. flet/components/utils.py +85 -0
  17. flet/controls/base_control.py +34 -10
  18. flet/controls/base_page.py +44 -40
  19. flet/controls/context.py +22 -1
  20. flet/controls/control.py +12 -6
  21. flet/controls/control_event.py +19 -2
  22. flet/controls/core/animated_switcher.py +3 -2
  23. flet/controls/core/autofill_group.py +6 -2
  24. flet/controls/core/column.py +5 -0
  25. flet/controls/core/dismissible.py +12 -10
  26. flet/controls/core/drag_target.py +20 -10
  27. flet/controls/core/draggable.py +9 -9
  28. flet/controls/core/icon.py +16 -12
  29. flet/controls/core/interactive_viewer.py +24 -23
  30. flet/controls/core/pagelet.py +3 -2
  31. flet/controls/core/reorderable_draggable.py +3 -2
  32. flet/controls/core/row.py +5 -0
  33. flet/controls/core/safe_area.py +3 -2
  34. flet/controls/core/text_span.py +5 -3
  35. flet/controls/core/view.py +6 -6
  36. flet/controls/core/window_drag_area.py +3 -2
  37. flet/controls/cupertino/cupertino_action_sheet.py +10 -5
  38. flet/controls/cupertino/cupertino_action_sheet_action.py +3 -4
  39. flet/controls/cupertino/cupertino_activity_indicator.py +4 -3
  40. flet/controls/cupertino/cupertino_alert_dialog.py +6 -3
  41. flet/controls/cupertino/cupertino_button.py +6 -5
  42. flet/controls/cupertino/cupertino_context_menu.py +8 -4
  43. flet/controls/cupertino/cupertino_context_menu_action.py +3 -4
  44. flet/controls/cupertino/cupertino_date_picker.py +44 -28
  45. flet/controls/cupertino/cupertino_dialog_action.py +3 -4
  46. flet/controls/cupertino/cupertino_list_tile.py +3 -4
  47. flet/controls/cupertino/cupertino_navigation_bar.py +6 -5
  48. flet/controls/cupertino/cupertino_picker.py +14 -10
  49. flet/controls/cupertino/cupertino_segmented_button.py +6 -5
  50. flet/controls/cupertino/cupertino_slider.py +16 -12
  51. flet/controls/cupertino/cupertino_sliding_segmented_button.py +6 -5
  52. flet/controls/cupertino/cupertino_timer_picker.py +38 -31
  53. flet/controls/id_counter.py +24 -0
  54. flet/controls/material/alert_dialog.py +6 -5
  55. flet/controls/material/app_bar.py +17 -14
  56. flet/controls/material/banner.py +13 -11
  57. flet/controls/material/bottom_app_bar.py +5 -4
  58. flet/controls/material/bottom_sheet.py +5 -4
  59. flet/controls/material/button.py +12 -4
  60. flet/controls/material/chip.py +13 -12
  61. flet/controls/material/circle_avatar.py +17 -13
  62. flet/controls/material/datatable.py +48 -41
  63. flet/controls/material/divider.py +30 -14
  64. flet/controls/material/dropdown.py +5 -3
  65. flet/controls/material/expansion_tile.py +11 -22
  66. flet/controls/material/floating_action_button.py +32 -23
  67. flet/controls/material/icon_button.py +7 -3
  68. flet/controls/material/navigation_rail.py +14 -11
  69. flet/controls/material/outlined_button.py +7 -3
  70. flet/controls/material/progress_bar.py +18 -10
  71. flet/controls/material/radio_group.py +5 -1
  72. flet/controls/material/range_slider.py +13 -13
  73. flet/controls/material/segmented_button.py +21 -17
  74. flet/controls/material/selection_area.py +3 -2
  75. flet/controls/material/slider.py +16 -12
  76. flet/controls/material/snack_bar.py +18 -10
  77. flet/controls/material/switch.py +6 -5
  78. flet/controls/material/tabs.py +18 -14
  79. flet/controls/material/textfield.py +32 -15
  80. flet/controls/material/vertical_divider.py +20 -12
  81. flet/controls/object_patch.py +434 -197
  82. flet/controls/page.py +205 -85
  83. flet/controls/services/haptic_feedback.py +0 -3
  84. flet/controls/services/shake_detector.py +0 -3
  85. flet/messaging/flet_socket_server.py +13 -6
  86. flet/messaging/session.py +103 -10
  87. flet/{controls/session_storage.py → messaging/session_store.py} +2 -2
  88. flet/version.py +1 -1
  89. {flet-0.70.0.dev5774.dist-info → flet-0.70.0.dev5835.dist-info}/METADATA +5 -5
  90. {flet-0.70.0.dev5774.dist-info → flet-0.70.0.dev5835.dist-info}/RECORD +93 -80
  91. flet/controls/cache.py +0 -87
  92. flet/controls/control_id.py +0 -22
  93. flet/controls/core/state_view.py +0 -60
  94. {flet-0.70.0.dev5774.dist-info → flet-0.70.0.dev5835.dist-info}/WHEEL +0 -0
  95. {flet-0.70.0.dev5774.dist-info → flet-0.70.0.dev5835.dist-info}/entry_points.txt +0 -0
  96. {flet-0.70.0.dev5774.dist-info → flet-0.70.0.dev5835.dist-info}/top_level.txt +0 -0
@@ -33,6 +33,9 @@ class ExpansionTile(LayoutControl, AdaptiveControl):
33
33
  """
34
34
  A single-line ListTile with an expansion arrow icon that expands or collapses the
35
35
  tile to reveal or hide its controls.
36
+
37
+ Raises:
38
+ ValueError: If [`title`][(c).] is neither a string nor a visible Control.
36
39
  """
37
40
 
38
41
  title: StrOrControl
@@ -108,28 +111,22 @@ class ExpansionTile(LayoutControl, AdaptiveControl):
108
111
  initially_expanded: bool = False
109
112
  """
110
113
  A boolean value which defines whether the tile is initially expanded or collapsed.
111
-
112
- Defaults to `False`.
113
114
  """
114
115
 
115
116
  maintain_state: bool = False
116
117
  """
117
118
  A boolean value which defines whether the state of the `controls` is maintained
118
119
  when the tile expands and collapses.
119
-
120
- Defaults to `False`.
121
120
  """
122
121
 
123
122
  text_color: Optional[ColorValue] = None
124
123
  """
125
- The color of the tile's titles when the
126
- sublist is expanded.
124
+ The color of the tile's titles when the sublist is expanded.
127
125
  """
128
126
 
129
127
  icon_color: Optional[ColorValue] = None
130
128
  """
131
- The icon color of tile's expansion arrow
132
- icon when the sublist is expanded.
129
+ The icon color of tile's expansion arrow icon when the sublist is expanded.
133
130
  """
134
131
 
135
132
  shape: Optional[OutlinedBorder] = None
@@ -139,26 +136,22 @@ class ExpansionTile(LayoutControl, AdaptiveControl):
139
136
 
140
137
  bgcolor: Optional[ColorValue] = None
141
138
  """
142
- The color to display behind the sublist
143
- when expanded.
139
+ The color to display behind the sublist when expanded.
144
140
  """
145
141
 
146
142
  collapsed_bgcolor: Optional[ColorValue] = None
147
143
  """
148
- Defines the background color of tile when
149
- the sublist is collapsed.
144
+ Defines the background color of tile when the sublist is collapsed.
150
145
  """
151
146
 
152
147
  collapsed_icon_color: Optional[ColorValue] = None
153
148
  """
154
- The icon color of tile's expansion arrow
155
- icon when the sublist is collapsed.
149
+ The icon color of tile's expansion arrow icon when the sublist is collapsed.
156
150
  """
157
151
 
158
152
  collapsed_text_color: Optional[ColorValue] = None
159
153
  """
160
- The color of the tile's titles when the
161
- sublist is collapsed.
154
+ The color of the tile's titles when the sublist is collapsed.
162
155
  """
163
156
 
164
157
  collapsed_shape: Optional[OutlinedBorder] = None
@@ -179,16 +172,12 @@ class ExpansionTile(LayoutControl, AdaptiveControl):
179
172
  Whether detected gestures should provide acoustic and/or haptic feedback. For
180
173
  example, on Android a tap will produce a clicking sound and a long-press will
181
174
  produce a short vibration, when feedback is enabled.
182
-
183
- Defaults to `True`.
184
175
  """
185
176
 
186
177
  show_trailing_icon: bool = True
187
178
  """
188
179
  Whether to show the trailing icon (be it the default icon or the custom `trailing`,
189
180
  if specified and visible).
190
-
191
- Defaults to `True`.
192
181
  """
193
182
 
194
183
  min_tile_height: Optional[Number] = None
@@ -208,5 +197,5 @@ class ExpansionTile(LayoutControl, AdaptiveControl):
208
197
 
209
198
  def before_update(self):
210
199
  super().before_update()
211
- if isinstance(self.title, Control):
212
- assert self.title.visible, "title must be visible"
200
+ if isinstance(self.title, Control) and not self.title.visible:
201
+ raise ValueError("title must be visible")
@@ -27,9 +27,9 @@ class FloatingActionButton(LayoutControl):
27
27
  place on a page.
28
28
 
29
29
  Raises:
30
- AssertionError: If neither [`icon`][(c).] nor a valid [`content`][(c).]
30
+ ValueError: If neither [`icon`][(c).] nor a valid [`content`][(c).]
31
31
  (string or visible Control) is provided.
32
- AssertionError: If [`elevation`][(c).],
32
+ ValueError: If [`elevation`][(c).],
33
33
  [`disabled_elevation`][(c).], [`focus_elevation`][(c).],
34
34
  [`highlight_elevation`][(c).], or [`hover_elevation`][(c).]
35
35
  is negative.
@@ -161,27 +161,36 @@ class FloatingActionButton(LayoutControl):
161
161
 
162
162
  def before_update(self):
163
163
  super().before_update()
164
- assert (
164
+ if not (
165
165
  self.icon
166
166
  or isinstance(self.content, str)
167
167
  or (isinstance(self.content, Control) and self.content.visible)
168
- ), "at minimum, icon or a content (string or visible Control) must be provided"
169
- assert self.elevation is None or self.elevation >= 0, (
170
- f"elevation must be greater than or equal to 0, got {self.elevation}"
171
- )
172
- assert self.disabled_elevation is None or self.disabled_elevation >= 0, (
173
- "disabled_elevation must be greater than or equal to 0, "
174
- f"got {self.disabled_elevation}"
175
- )
176
- assert self.focus_elevation is None or self.focus_elevation >= 0, (
177
- "focus_elevation must be greater than or equal to 0, "
178
- f"got {self.focus_elevation}"
179
- )
180
- assert self.highlight_elevation is None or self.highlight_elevation >= 0, (
181
- "highlight_elevation must be greater than or equal to 0, "
182
- f"got {self.highlight_elevation}"
183
- )
184
- assert self.hover_elevation is None or self.hover_elevation >= 0, (
185
- "hover_elevation must be greater than or equal to 0, "
186
- f"got {self.hover_elevation}"
187
- )
168
+ ):
169
+ raise ValueError(
170
+ "at minimum, icon or a content (string or visible Control) "
171
+ "must be provided"
172
+ )
173
+ if self.elevation is not None and self.elevation < 0:
174
+ raise ValueError(
175
+ f"elevation must be greater than or equal to 0, got {self.elevation}"
176
+ )
177
+ if self.disabled_elevation is not None and self.disabled_elevation < 0:
178
+ raise ValueError(
179
+ "disabled_elevation must be greater than or equal to 0, "
180
+ f"got {self.disabled_elevation}"
181
+ )
182
+ if self.focus_elevation is not None and self.focus_elevation < 0:
183
+ raise ValueError(
184
+ "focus_elevation must be greater than or equal to 0, "
185
+ f"got {self.focus_elevation}"
186
+ )
187
+ if self.highlight_elevation is not None and self.highlight_elevation < 0:
188
+ raise ValueError(
189
+ "highlight_elevation must be greater than or equal to 0, "
190
+ f"got {self.highlight_elevation}"
191
+ )
192
+ if self.hover_elevation is not None and self.hover_elevation < 0:
193
+ raise ValueError(
194
+ "hover_elevation must be greater than or equal to 0, "
195
+ f"got {self.hover_elevation}"
196
+ )
@@ -34,6 +34,9 @@ class IconButton(LayoutControl, AdaptiveControl):
34
34
 
35
35
  Icon buttons are commonly used in the toolbars, but they can be used in many other
36
36
  places as well.
37
+
38
+ Raises:
39
+ ValueError: If [`splash_radius`][(c).] is not greater than `0`.
37
40
  """
38
41
 
39
42
  icon: Optional[IconDataOrControl] = None
@@ -200,9 +203,10 @@ class IconButton(LayoutControl, AdaptiveControl):
200
203
 
201
204
  def before_update(self):
202
205
  super().before_update()
203
- assert self.splash_radius is None or self.splash_radius > 0, (
204
- f"splash_radius must be greater than 0, got {self.splash_radius}"
205
- )
206
+ if self.splash_radius is not None and self.splash_radius <= 0:
207
+ raise ValueError(
208
+ f"splash_radius must be greater than 0, got {self.splash_radius}"
209
+ )
206
210
  if (
207
211
  self.style is not None
208
212
  or self.bgcolor is not None
@@ -28,7 +28,7 @@ class NavigationRailLabelType(Enum):
28
28
  @control("NavigationRailDestination")
29
29
  class NavigationRailDestination(Control):
30
30
  """
31
- TBD
31
+ Represents a destination in a `NavigationRail`.
32
32
  """
33
33
 
34
34
  icon: Optional[IconDataOrControl] = None
@@ -81,6 +81,11 @@ class NavigationRail(LayoutControl):
81
81
  """
82
82
  A material widget that is meant to be displayed at the left or right of an app to
83
83
  navigate between a small number of views, typically between three and five.
84
+
85
+ Raises:
86
+ ValueError: If [`elevation`][(c).] is negative.
87
+ ValueError: If [`min_width`][(c).] is negative.
88
+ ValueError: If [`min_extended_width`][(c).] is negative.
84
89
  """
85
90
 
86
91
  destinations: list[NavigationRailDestination] = field(default_factory=list)
@@ -130,14 +135,12 @@ class NavigationRail(LayoutControl):
130
135
 
131
136
  bgcolor: Optional[ColorValue] = None
132
137
  """
133
- Sets the color of the Container that holds
134
- all of the NavigationRail's contents.
138
+ Sets the color of the Container that holds all of the NavigationRail's contents.
135
139
  """
136
140
 
137
141
  indicator_color: Optional[ColorValue] = None
138
142
  """
139
- The color of the navigation rail's
140
- indicator.
143
+ The color of the navigation rail's indicator.
141
144
  """
142
145
 
143
146
  indicator_shape: Optional[OutlinedBorder] = None
@@ -241,9 +244,9 @@ class NavigationRail(LayoutControl):
241
244
 
242
245
  def before_update(self):
243
246
  super().before_update()
244
- if self.elevation is not None:
245
- assert self.elevation >= 0, "elevation cannot be negative"
246
- if self.min_width is not None:
247
- assert self.min_width >= 0, "min_width cannot be negative"
248
- if self.min_extended_width is not None:
249
- assert self.min_extended_width >= 0, "min_extended_width cannot be negative"
247
+ if self.elevation is not None and self.elevation < 0:
248
+ raise ValueError("elevation cannot be negative")
249
+ if self.min_width is not None and self.min_width < 0:
250
+ raise ValueError("min_width cannot be negative")
251
+ if self.min_extended_width is not None and self.min_extended_width < 0:
252
+ raise ValueError("min_extended_width cannot be negative")
@@ -21,8 +21,11 @@ __all__ = ["OutlinedButton"]
21
21
  class OutlinedButton(LayoutControl, AdaptiveControl):
22
22
  """
23
23
  Outlined buttons are medium-emphasis buttons. They contain actions that are
24
- important, but arent the primary action in an app. Outlined buttons pair well with
24
+ important, but aren't the primary action in an app. Outlined buttons pair well with
25
25
  filled buttons to indicate an alternative, secondary action.
26
+
27
+ Raises:
28
+ ValueError: If neither [`icon`][(c).] nor [`content`][(c).] is provided.
26
29
  """
27
30
 
28
31
  content: Optional[StrOrControl] = None
@@ -95,11 +98,12 @@ class OutlinedButton(LayoutControl, AdaptiveControl):
95
98
 
96
99
  def before_update(self):
97
100
  super().before_update()
98
- assert (
101
+ if not (
99
102
  self.icon
100
103
  or isinstance(self.content, str)
101
104
  or (isinstance(self.content, Control) and self.content.visible)
102
- ), "at minimum, icon or a visible content must be provided"
105
+ ):
106
+ raise ValueError("at minimum, icon or a visible content must be provided")
103
107
 
104
108
  async def focus(self):
105
109
  await self._invoke_method("focus")
@@ -14,6 +14,11 @@ class ProgressBar(LayoutControl):
14
14
  A material design linear progress indicator, also known as a progress bar.
15
15
 
16
16
  A control that shows progress along a line.
17
+
18
+ Raises:
19
+ ValueError: If [`value`][(c).] is negative.
20
+ ValueError: If [`bar_height`][(c).] is negative.
21
+ ValueError: If [`semantics_value`][(c).] is negative.
17
22
  """
18
23
 
19
24
  value: Optional[Number] = None
@@ -114,13 +119,16 @@ class ProgressBar(LayoutControl):
114
119
 
115
120
  def before_update(self):
116
121
  super().before_update()
117
- assert self.value is None or self.value >= 0, (
118
- f"value must be greater than or equal to 0, got {self.value}"
119
- )
120
- assert self.bar_height is None or self.bar_height >= 0, (
121
- f"bar_height must be greater than or equal to 0, got {self.bar_height}"
122
- )
123
- assert self.semantics_value is None or self.semantics_value >= 0, (
124
- f"semantics_value must be greater than or equal to 0, "
125
- f"got {self.semantics_value}"
126
- )
122
+ if self.value is not None and self.value < 0:
123
+ raise ValueError(
124
+ f"value must be greater than or equal to 0, got {self.value}"
125
+ )
126
+ if self.bar_height is not None and self.bar_height < 0:
127
+ raise ValueError(
128
+ f"bar_height must be greater than or equal to 0, got {self.bar_height}"
129
+ )
130
+ if self.semantics_value is not None and self.semantics_value < 0:
131
+ raise ValueError(
132
+ f"semantics_value must be greater than or equal to 0, "
133
+ f"got {self.semantics_value}"
134
+ )
@@ -11,6 +11,9 @@ __all__ = ["RadioGroup"]
11
11
  class RadioGroup(Control):
12
12
  """
13
13
  Radio buttons let people select a single option from two or more choices.
14
+
15
+ Raises:
16
+ ValueError: If [`content`][(c).] is not visible.
14
17
  """
15
18
 
16
19
  content: Control
@@ -33,4 +36,5 @@ class RadioGroup(Control):
33
36
 
34
37
  def before_update(self):
35
38
  super().before_update()
36
- assert self.content.visible, "content must be visible"
39
+ if not self.content.visible:
40
+ raise ValueError("content must be visible")
@@ -20,6 +20,11 @@ class RangeSlider(LayoutControl):
20
20
  A range slider can be used to select from either a continuous or a discrete
21
21
  set of values.
22
22
  The default is to use a continuous range of values from min to max.
23
+
24
+ Raises:
25
+ ValueError: If [`end_value`][(c).] is greater than [`max`][(c).].
26
+ ValueError: If [`start_value`][(c).] is less than [`min`][(c).].
27
+ ValueError: If [`start_value`][(c).] is greater than [`end_value`][(c).].
23
28
  """
24
29
 
25
30
  start_value: Number
@@ -124,17 +129,12 @@ class RangeSlider(LayoutControl):
124
129
  """
125
130
 
126
131
  def before_update(self):
127
- if self.max is not None:
128
- assert self.end_value <= self.max, (
129
- "end_value must be less than or equal to max"
130
- )
131
-
132
- if self.min is not None:
133
- assert self.start_value >= self.min, (
134
- "start_value must be greater than or equal to min"
135
- )
136
-
137
- assert self.start_value <= self.end_value, (
138
- "start_value must be less than or equal to end_value"
139
- )
132
+ if self.max is not None and self.end_value > self.max:
133
+ raise ValueError("end_value must be less than or equal to max")
134
+
135
+ if self.min is not None and self.start_value < self.min:
136
+ raise ValueError("start_value must be greater than or equal to min")
137
+
138
+ if self.start_value > self.end_value:
139
+ raise ValueError("start_value must be less than or equal to end_value")
140
140
  pass
@@ -23,7 +23,7 @@ class Segment(Control):
23
23
  A segment for a [`SegmentedButton`][flet.].
24
24
 
25
25
  Raises:
26
- AssertionError: If neither [`icon`][(c).] nor [`label`][(c).] is set.
26
+ ValueError: If neither [`icon`][(c).] nor [`label`][(c).] is set.
27
27
  """
28
28
 
29
29
  value: str
@@ -45,12 +45,13 @@ class Segment(Control):
45
45
 
46
46
  def before_update(self):
47
47
  super().before_update()
48
- assert (
48
+ if not (
49
49
  (isinstance(self.icon, IconData))
50
50
  or (isinstance(self.icon, Control) and self.icon.visible)
51
51
  or (isinstance(self.label, str))
52
52
  or (isinstance(self.label, Control) and self.label.visible)
53
- ), "one of icon or label must be set and visible"
53
+ ):
54
+ raise ValueError("one of icon or label must be set and visible")
54
55
 
55
56
 
56
57
  @control("SegmentedButton")
@@ -59,11 +60,13 @@ class SegmentedButton(LayoutControl):
59
60
  A segmented button control.
60
61
 
61
62
  Raises:
62
- AssertionError: If [`segments`][(c).] is empty or does not have at
63
+ ValueError: If [`segments`][(c).] is empty or does not have at
63
64
  least one visible `Segment`.
64
- AssertionError: If [`selected`][(c).] is empty and [`allow_empty_selection`][(c).] is `False`.
65
- AssertionError: If [`selected`][(c).] has more than one item and [`allow_multiple_selection`][(c).] is `False`.
66
- """ # noqa: E501
65
+ ValueError: If [`selected`][(c).] is empty and
66
+ [`allow_empty_selection`][(c).] is `False`.
67
+ ValueError: If [`selected`][(c).] has more than one item and
68
+ [`allow_multiple_selection`][(c).] is `False`.
69
+ """
67
70
 
68
71
  segments: list[Segment]
69
72
  """
@@ -153,13 +156,14 @@ class SegmentedButton(LayoutControl):
153
156
 
154
157
  def before_update(self):
155
158
  super().before_update()
156
- assert any(segment.visible for segment in self.segments), (
157
- "segments must have at minimum one visible Segment"
158
- )
159
- assert len(self.selected) > 0 or self.allow_empty_selection, (
160
- "allow_empty_selection must be True for selected to be empty"
161
- )
162
- assert len(self.selected) < 2 or self.allow_multiple_selection, (
163
- "allow_multiple_selection must be True for selected "
164
- "to have more than one item"
165
- )
159
+ if not any(segment.visible for segment in self.segments):
160
+ raise ValueError("segments must have at minimum one visible Segment")
161
+ if len(self.selected) == 0 and not self.allow_empty_selection:
162
+ raise ValueError(
163
+ "allow_empty_selection must be True for selected to be empty"
164
+ )
165
+ if len(self.selected) >= 2 and not self.allow_multiple_selection:
166
+ raise ValueError(
167
+ "allow_multiple_selection must be True for selected to "
168
+ "have more than one item"
169
+ )
@@ -14,7 +14,7 @@ class SelectionArea(Control):
14
14
  selection for its child control.
15
15
 
16
16
  Raises:
17
- AssertionError: If [`content`][(c).] is not visible
17
+ ValueError: If [`content`][(c).] is not visible
18
18
  """
19
19
 
20
20
  content: Control
@@ -33,4 +33,5 @@ class SelectionArea(Control):
33
33
 
34
34
  def before_update(self):
35
35
  super().before_update()
36
- assert self.content.visible, "content must be visible"
36
+ if not self.content.visible:
37
+ raise ValueError("content must be visible")
@@ -34,9 +34,9 @@ class Slider(LayoutControl, AdaptiveControl):
34
34
  of setting changes.
35
35
 
36
36
  Raises:
37
- AssertionError: If [`min`][(c).] is greater than or equal to [`max`][(c).].
38
- AssertionError: If [`min`][(c).] is greater than or equal to [`value`][(c).].
39
- AssertionError: If [`max`][(c).] is less than or equal to [`value`][(c).].
37
+ ValueError: If [`min`][(c).] is greater than [`max`][(c).].
38
+ ValueError: If [`value`][(c).] is less than [`min`][(c).].
39
+ ValueError: If [`value`][(c).] is greater than [`max`][(c).].
40
40
  """
41
41
 
42
42
  value: Optional[Number] = None
@@ -216,12 +216,16 @@ class Slider(LayoutControl, AdaptiveControl):
216
216
 
217
217
  def before_update(self):
218
218
  super().before_update()
219
- assert self.max is None or self.min <= self.max, (
220
- f"min ({self.min}) must be less than or equal to max ({self.max})"
221
- )
222
- assert self.value is None or self.value >= self.min, (
223
- f"value ({self.value}) must be greater than or equal to min ({self.min})"
224
- )
225
- assert self.value is None or self.value <= self.max, (
226
- f"value ({self.value}) must be less than or equal to max ({self.max})"
227
- )
219
+ if self.max is not None and self.min > self.max:
220
+ raise ValueError(
221
+ f"min ({self.min}) must be less than or equal to max ({self.max})"
222
+ )
223
+ if self.value is not None and self.value < self.min:
224
+ raise ValueError(
225
+ f"value ({self.value}) must be greater than or "
226
+ f"equal to min ({self.min})"
227
+ )
228
+ if self.value is not None and self.value > self.max:
229
+ raise ValueError(
230
+ f"value ({self.value}) must be less than or equal to max ({self.max})"
231
+ )
@@ -93,6 +93,11 @@ class SnackBar(DialogControl):
93
93
  """
94
94
  A lightweight message with an optional action which briefly displays at the
95
95
  bottom of the screen.
96
+
97
+ Raises:
98
+ ValueError: If [`content`][(c).] is not a string or visible control.
99
+ ValueError: If [`action_overflow_threshold`][(c).] is not between 0 and 1.
100
+ ValueError: If [`elevation`][(c).] is negative.
96
101
  """
97
102
 
98
103
  content: StrOrControl
@@ -229,13 +234,16 @@ class SnackBar(DialogControl):
229
234
 
230
235
  def before_update(self):
231
236
  super().before_update()
232
- assert isinstance(self.content, str) or (
233
- isinstance(self.content, Control) and self.content.visible
234
- ), "content must be a string or a visible control"
235
- assert (
236
- self.action_overflow_threshold is None
237
- or 0 <= self.action_overflow_threshold <= 1
238
- ), "action_overflow_threshold must be between 0 and 1 inclusive"
239
- assert self.elevation is None or self.elevation >= 0, (
240
- "elevation cannot be negative"
241
- )
237
+ if not (
238
+ isinstance(self.content, str)
239
+ or (isinstance(self.content, Control) and self.content.visible)
240
+ ):
241
+ raise ValueError("content must be a string or a visible control")
242
+ if self.action_overflow_threshold is not None and not (
243
+ 0 <= self.action_overflow_threshold <= 1
244
+ ):
245
+ raise ValueError(
246
+ "action_overflow_threshold must be between 0 and 1 inclusive"
247
+ )
248
+ if self.elevation is not None and self.elevation < 0:
249
+ raise ValueError("elevation cannot be negative")
@@ -28,7 +28,7 @@ class Switch(LayoutControl, AdaptiveControl):
28
28
  For example, "On/Off", "Show/Hide".
29
29
 
30
30
  Raises:
31
- AssertionError: If [`splash_radius`][(c).] is negative.
31
+ ValueError: If [`splash_radius`][(c).] is negative.
32
32
  """
33
33
 
34
34
  label: Optional[StrOrControl] = None
@@ -225,7 +225,8 @@ class Switch(LayoutControl, AdaptiveControl):
225
225
 
226
226
  def before_update(self):
227
227
  super().before_update()
228
- assert self.splash_radius is None or self.splash_radius >= 0, (
229
- "splash_radius must be greater than or equal to 0, "
230
- f"got {self.splash_radius}"
231
- )
228
+ if self.splash_radius is not None and self.splash_radius < 0:
229
+ raise ValueError(
230
+ "splash_radius must be greater than or equal to 0, "
231
+ f"got {self.splash_radius}"
232
+ )
@@ -316,9 +316,9 @@ class TabBar(LayoutControl, AdaptiveControl):
316
316
  on text headers to articulate the different sections of content.
317
317
 
318
318
  Raises:
319
- AssertionError: If [`indicator`][(c).] is None and
319
+ ValueError: If [`indicator`][(c).] is None and
320
320
  [`indicator_thickness`][(c).] is not strictly greater than 0.
321
- AssertionError: If [`tab_alignment`][(c).] is not valid for
321
+ ValueError: If [`tab_alignment`][(c).] is not valid for
322
322
  the given [`scrollable`][(c).] state.
323
323
  """
324
324
 
@@ -538,20 +538,25 @@ class TabBar(LayoutControl, AdaptiveControl):
538
538
 
539
539
  def before_update(self):
540
540
  super().before_update()
541
- assert self.indicator is not None or self.indicator_thickness > 0.0, (
542
- f"indicator_thickness must be strictly greater than zero if indicator is "
543
- f"None, got {self.indicator_thickness}"
544
- )
541
+ if self.indicator is None and self.indicator_thickness <= 0.0:
542
+ raise ValueError(
543
+ f"indicator_thickness must be strictly greater than zero if indicator "
544
+ f"is None, got {self.indicator_thickness}"
545
+ )
545
546
  valid_alignments = (
546
547
  [TabAlignment.CENTER, TabAlignment.FILL]
547
548
  if not self.scrollable
548
549
  else [TabAlignment.START, TabAlignment.START_OFFSET, TabAlignment.CENTER]
549
550
  )
550
551
 
551
- assert self.tab_alignment is None or self.tab_alignment in valid_alignments, (
552
- f"If scrollable is {self.scrollable}, tab_alignment must be one of: "
553
- f"{', '.join(f'TabAlignment.{a.name}' for a in valid_alignments)}."
554
- )
552
+ if (
553
+ self.tab_alignment is not None
554
+ and self.tab_alignment not in valid_alignments
555
+ ):
556
+ raise ValueError(
557
+ f"If scrollable is {self.scrollable}, tab_alignment must be one of: "
558
+ f"{', '.join(f'TabAlignment.{a.name}' for a in valid_alignments)}."
559
+ )
555
560
 
556
561
 
557
562
  @control("Tab")
@@ -560,7 +565,7 @@ class Tab(AdaptiveControl):
560
565
  A Material Design [`TabBar`][flet.] tab.
561
566
 
562
567
  Raises:
563
- AssertionError: If both [`label`][(c).] and [`icon`][(c).] are not set.
568
+ ValueError: If both [`label`][(c).] and [`icon`][(c).] are not set.
564
569
  """
565
570
 
566
571
  label: Optional[StrOrControl] = None
@@ -599,6 +604,5 @@ class Tab(AdaptiveControl):
599
604
 
600
605
  def before_update(self):
601
606
  super().before_update()
602
- assert (self.label is not None) or (self.icon is not None), (
603
- "Tab must have at least label or icon property set"
604
- )
607
+ if not ((self.label is not None) or (self.icon is not None)):
608
+ raise ValueError("Tab must have at least label or icon property set")