Skip to content

Commit

Permalink
Cleanup (#3406)
Browse files Browse the repository at this point in the history
* cleanup

* TimePicker/DatePicker: deprecate pick_time

* FlashLight: await coroutines

* Usercontrol: deprecation well done

* fix bugs

* Cleanup

* reformat

* Page: type hint for *controls __update

* Page: added open/close + deprecated open_* and close_* functions

* update handler's typing

* pass flutter 3.22.1 CI build

* update deprecation delete_version

* Review commit: replace overlay by __offstage.controls

Co-authored-by: Feodor Fitsner <[email protected]>

---------

Co-authored-by: Feodor Fitsner <[email protected]>
  • Loading branch information
ndonkoHenri and FeodorFitsner authored Jun 10, 2024
1 parent ae32b43 commit 2d64dbc
Show file tree
Hide file tree
Showing 49 changed files with 743 additions and 668 deletions.
2 changes: 0 additions & 2 deletions packages/flet_map/lib/src/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class _MapControlState extends State<MapControl> with FletStoreMixin {
keepAlive: config.control.attrBool("keepAlive", false)!,
maxZoom: config.control.attrDouble("maxZoom"),
minZoom: config.control.attrDouble("minZoom"),
interactionOptions: parseInteractionOptions(
config.control, "interactionConfiguration"),
onTap: onTap
? (TapPosition pos, LatLng latlng) {
triggerEvent(config.control, "tap", {
Expand Down
1 change: 0 additions & 1 deletion packages/flet_map/lib/src/polygon_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class PolygonLayerControl extends StatelessWidget with FletStoreMixin {
const Color(0xFFFFFF00),
color: polygon.control.attrColor("color", context) ??
const Color(0xFF00FF00),
isDotted: polygon.control.attrBool("dotted", false)!,
disableHolesBorder:
polygon.control.attrBool("disableHolesBorder", false)!,
rotateLabel: polygon.control.attrBool("rotateLabel", false)!,
Expand Down
1 change: 0 additions & 1 deletion packages/flet_map/lib/src/polyline_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class PolylineLayerControl extends StatelessWidget with FletStoreMixin {
.attrColor("borderColor", context, const Color(0xFFFFFF00))!,
color: polyline.control
.attrColor("color", context, const Color(0xFF00FF00))!,
isDotted: polyline.control.attrBool("dotted", false)!,
strokeCap: parseStrokeCap(
polyline.control.attrString("strokeCap"), StrokeCap.round)!,
strokeJoin: parseStrokeJoin(
Expand Down
1 change: 0 additions & 1 deletion packages/flet_map/lib/src/utils/map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ InteractionOptions interactionOptionsFromJSON(dynamic json) {
return InteractionOptions(
enableMultiFingerGestureRace:
parseBool(json["enable_multi_finger_gesture_race"], false)!,
enableScrollWheel: parseBool(json["enable_scroll_wheel"], false)!,
pinchMoveThreshold: parseDouble(json["pinch_move_threshold"], 40.0)!,
scrollWheelVelocity: parseDouble(json["scroll_wheel_velocity"], 0.005)!,
pinchZoomThreshold: parseDouble(json["pinch_zoom_threshold"], 0.5)!,
Expand Down
11 changes: 7 additions & 4 deletions sdk/python/packages/flet-core/src/flet_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,14 @@
from flet_core.navigation_bar import (
NavigationBar,
NavigationBarDestination,
NavigationDestination,
NavigationBarLabelBehavior,
)
from flet_core.navigation_drawer import NavigationDrawer, NavigationDrawerDestination
from flet_core.navigation_drawer import (
NavigationDrawer,
NavigationDrawerDestination,
NavigationDrawerPosition,
)
from flet_core.navigation_rail import (
NavigationRail,
NavigationRailDestination,
Expand Down Expand Up @@ -317,12 +322,10 @@
BoxShape,
Brightness,
ClipBehavior,
ColorStr,
ControlEventFunction,
OptionalEventCallback,
CrossAxisAlignment,
FloatingActionButtonLocation,
FontWeight,
IconStr,
ImageFit,
ImageRepeat,
LabelPosition,
Expand Down
45 changes: 23 additions & 22 deletions sdk/python/packages/flet-core/src/flet_core/alert_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
from flet_core.control import Control, OptionalNumber
from flet_core.ref import Ref
from flet_core.text_style import TextStyle
from flet_core.types import ClipBehavior, MainAxisAlignment, PaddingValue
from flet_core.types import (
ClipBehavior,
MainAxisAlignment,
PaddingValue,
OptionalEventCallback,
)


class AlertDialog(AdaptiveControl):
Expand All @@ -17,44 +22,40 @@ class AlertDialog(AdaptiveControl):
```
import flet as ft
def main(page: ft.Page):
page.title = "AlertDialog examples"
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
dlg = ft.AlertDialog(
title=ft.Text("Hello, you!"), on_dismiss=lambda e: print("Dialog dismissed!")
title=ft.Text("Hi, this is a non-modal dialog!"),
on_dismiss=lambda e: page.add(ft.Text("Non-modal dialog dismissed")),
)
def close_dlg(e):
dlg_modal.open = False
page.update()
def handle_close(e):
page.close(dlg_modal)
page.add(ft.Text(f"Modal dialog closed with action: {e.control.text}"))
dlg_modal = ft.AlertDialog(
modal=True,
title=ft.Text("Please confirm"),
content=ft.Text("Do you really want to delete all those files?"),
actions=[
ft.TextButton("Yes", on_click=close_dlg),
ft.TextButton("No", on_click=close_dlg),
ft.TextButton("Yes", on_click=handle_close),
ft.TextButton("No", on_click=handle_close),
],
actions_alignment=ft.MainAxisAlignment.END,
on_dismiss=lambda e: print("Modal dialog dismissed!"),
on_dismiss=lambda e: page.add(
ft.Text("Modal dialog dismissed"),
),
)
def open_dlg(e):
page.dialog = dlg
dlg.open = True
page.update()
def open_dlg_modal(e):
page.dialog = dlg_modal
dlg_modal.open = True
page.update()
page.add(
ft.ElevatedButton("Open dialog", on_click=open_dlg),
ft.ElevatedButton("Open modal dialog", on_click=open_dlg_modal),
ft.ElevatedButton("Open dialog", on_click=lambda e: page.open(dlg)),
ft.ElevatedButton("Open modal dialog", on_click=lambda e: page.open(dlg_modal)),
)
ft.app(target=main)
```
-----
Expand Down Expand Up @@ -90,7 +91,7 @@ def __init__(
title_text_style: Optional[TextStyle] = None,
clip_behavior: Optional[ClipBehavior] = None,
semantics_label: Optional[str] = None,
on_dismiss=None,
on_dismiss: OptionalEventCallback = None,
#
# AdaptiveControl
#
Expand Down Expand Up @@ -420,5 +421,5 @@ def on_dismiss(self):
return self._get_event_handler("dismiss")

@on_dismiss.setter
def on_dismiss(self, handler):
def on_dismiss(self, handler: OptionalEventCallback):
self._add_event_handler("dismiss", handler)
10 changes: 5 additions & 5 deletions sdk/python/packages/flet-core/src/flet_core/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def play(self):
@deprecated(
reason="Use play() method instead.",
version="0.21.0",
delete_version="1.0",
delete_version="0.26.0",
)
async def play_async(self):
self.play()
Expand All @@ -99,7 +99,7 @@ def pause(self):
@deprecated(
reason="Use pause() method instead.",
version="0.21.0",
delete_version="1.0",
delete_version="0.26.0",
)
async def pause_async(self):
self.pause()
Expand All @@ -110,7 +110,7 @@ def resume(self):
@deprecated(
reason="Use resume() method instead.",
version="0.21.0",
delete_version="1.0",
delete_version="0.26.0",
)
async def resume_async(self):
self.resume()
Expand All @@ -121,7 +121,7 @@ def release(self):
@deprecated(
reason="Use release() method instead.",
version="0.21.0",
delete_version="1.0",
delete_version="0.26.0",
)
async def release_async(self):
self.release()
Expand All @@ -132,7 +132,7 @@ def seek(self, position_milliseconds: int):
@deprecated(
reason="Use seek() method instead.",
version="0.21.0",
delete_version="1.0",
delete_version="0.26.0",
)
async def seek_async(self, position_milliseconds: int):
self.seek(position_milliseconds)
Expand Down
6 changes: 3 additions & 3 deletions sdk/python/packages/flet-core/src/flet_core/audio_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def start_recording(
@deprecated(
reason="Use start_recording() method instead.",
version="0.21.0",
delete_version="1.0",
delete_version="0.26.0",
)
async def start_recording_async(self, output_path: str) -> bool:
return self.start_recording(output_path)
Expand Down Expand Up @@ -123,7 +123,7 @@ def resume_recording(self):
@deprecated(
reason="Use resume_recording() method instead.",
version="0.21.0",
delete_version="1.0",
delete_version="0.26.0",
)
async def resume_recording_async(self):
self.resume_recording()
Expand All @@ -134,7 +134,7 @@ def pause_recording(self):
@deprecated(
reason="Use pause_recording() method instead.",
version="0.21.0",
delete_version="1.0",
delete_version="0.26.0",
)
async def pause_recording_async(self):
self.pause_recording()
Expand Down
26 changes: 14 additions & 12 deletions sdk/python/packages/flet-core/src/flet_core/banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,33 @@ class Banner(Control):
```
import flet as ft
def main(page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
def close_banner(e):
page.banner.open = False
page.update()
page.close(banner)
page.add(ft.Text("Action clicked: " + e.control.text))
page.banner = ft.Banner(
action_button_style = ft.ButtonStyle(color=ft.colors.BLUE)
banner = ft.Banner(
bgcolor=ft.colors.AMBER_100,
leading=ft.Icon(ft.icons.WARNING_AMBER_ROUNDED, color=ft.colors.AMBER, size=40),
content=ft.Text(
"Oops, there were some errors while trying to delete the file. What would you like me to do?"
value="Oops, there were some errors while trying to delete the file. What would you like me to do?",
color=ft.colors.BLACK,
),
actions=[
ft.TextButton("Retry", on_click=close_banner),
ft.TextButton("Ignore", on_click=close_banner),
ft.TextButton("Cancel", on_click=close_banner),
ft.TextButton(text="Retry", style=action_button_style, on_click=close_banner),
ft.TextButton(text="Ignore", style=action_button_style, on_click=close_banner),
ft.TextButton(text="Cancel", style=action_button_style, on_click=close_banner),
],
)
def show_banner_click(e):
page.banner.open = True
page.update()
page.add(ft.ElevatedButton("Show Banner", on_click=lambda e: page.open(banner)))
page.add(ft.ElevatedButton("Show Banner", on_click=show_banner_click))
ft.app(target=main)
ft.app(main)
```
-----
Expand Down
35 changes: 14 additions & 21 deletions sdk/python/packages/flet-core/src/flet_core/bottom_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,27 @@ class BottomSheet(Control):
```
import flet as ft
def main(page: ft.Page):
def bs_dismissed(e):
print("Dismissed!")
def show_bs(e):
bs.open = True
bs.update()
def close_bs(e):
bs.open = False
bs.update()
def main(page: ft.Page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
def handle_dismissal(e):
page.add(ft.Text("Bottom sheet dismissed"))
bs = ft.BottomSheet(
ft.Container(
ft.Column(
[
ft.Text("This is sheet's content!"),
ft.ElevatedButton("Close bottom sheet", on_click=close_bs),
],
on_dismiss=handle_dismissal,
content=ft.Container(
padding=50,
content=ft.Column(
tight=True,
controls=[
ft.Text("This is bottom sheet's content!"),
ft.ElevatedButton("Close bottom sheet", on_click=lambda _: page.close(bs)),
],
),
padding=10,
),
open=True,
on_dismiss=bs_dismissed,
)
page.overlay.append(bs)
page.add(ft.ElevatedButton("Display bottom sheet", on_click=show_bs))
page.add(ft.ElevatedButton("Display bottom sheet", on_click=lambda _: page.open(bs)))
ft.app(target=main)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def clean(self):
self.__shapes.clear()

@deprecated(
reason="Use clean() method instead.", version="0.21.0", delete_version="1.0"
reason="Use clean() method instead.", version="0.21.0", delete_version="0.26.0"
)
async def clean_async(self):
self.clean()
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/packages/flet-core/src/flet_core/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def clean(self):
@deprecated(
reason="Use clean() method instead.",
version="0.21.0",
delete_version="1.0",
delete_version="0.26.0",
)
async def clean_async(self):
self.clean()
Expand Down
24 changes: 16 additions & 8 deletions sdk/python/packages/flet-core/src/flet_core/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
from flet_core.embed_json_encoder import EmbedJsonEncoder
from flet_core.protocol import Command
from flet_core.ref import Ref
from flet_core.types import OptionalNumber, ResponsiveNumber, SupportsStr
from flet_core.types import (
OptionalNumber,
ResponsiveNumber,
SupportsStr,
OptionalEventCallback,
)
from flet_core.utils import deprecated

if TYPE_CHECKING:
Expand Down Expand Up @@ -67,7 +72,7 @@ def __init__(
self.data = data
self.rtl = rtl

self.__event_handlers = {}
self.__event_handlers: Dict[str, OptionalEventCallback] = {}
self.parent: Optional[Control] = None

def is_isolated(self) -> bool:
Expand Down Expand Up @@ -96,10 +101,12 @@ def _get_control_name(self) -> str:
"_get_control_name must be overridden in inherited class"
)

def _add_event_handler(self, event_name: str, handler) -> None:
def _add_event_handler(
self, event_name: str, handler: OptionalEventCallback
) -> None:
self.__event_handlers[event_name] = handler

def _get_event_handler(self, event_name: str):
def _get_event_handler(self, event_name: str) -> OptionalEventCallback:
return self.__event_handlers.get(event_name)

def _get_attr(
Expand Down Expand Up @@ -260,9 +267,10 @@ def opacity(self) -> Optional[float]:
return self._get_attr("opacity", data_type="float", def_value=1.0)

@opacity.setter
def opacity(self, value: Optional[float]):
if value:
value = max(0.0, min(value, 1.0)) # make sure 0.0 <= value <= 1.0
def opacity(self, value: OptionalNumber):
assert (
value is None or 0.0 <= value <= 1.0
), "opacity must be between 0.0 and 1.0"
self._set_attr("opacity", value)

# tooltip
Expand Down Expand Up @@ -315,7 +323,7 @@ def clean(self) -> None:
self.__page._clean(self)

@deprecated(
reason="Use clean() method instead.", version="0.21.0", delete_version="1.0"
reason="Use clean() method instead.", version="0.21.0", delete_version="0.26.0"
)
async def clean_async(self):
self.clean()
Expand Down
Loading

0 comments on commit 2d64dbc

Please sign in to comment.