Skip to content

Commit e818abd

Browse files
authored
Inesa/v1 docstrings cupertino (#5291)
* docstrings * CupertinoActionSheet docstrings and types * docstrings * docstrings * docstrings * docstrings * docstrings * CupertinoCheckbox description * docstrings * Update cupertino_colors.py * docstrings * docstrings * formatting for ruf * docstrings * Update cupertino_filled_button.py * Control description * docstrings and types * CupertinoDialogAction description * Update cupertino_list_tile.py * docstrings * Update cupertino_navigation_bar.py * docstrings * Update cupertino_picker.py * docstrings * docstrings * docstrings * Control description * docstrings * Update cupertino_sliding_segmented_button.py * docstrings * Update cupertino_switch.py * docstrings * docstrings * docstrings * Update cupertino_tinted_button.py
1 parent 290c6b4 commit e818abd

28 files changed

+1306
-340
lines changed

packages/flet/lib/src/controls/cupertino_action_sheet.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class CupertinoActionSheetControl extends StatelessWidget {
1414
debugPrint("CupertinoActionSheetControl build: ${control.id}");
1515

1616
var sheet = CupertinoActionSheet(
17-
title: control.buildWidget("title"),
18-
message: control.buildWidget("message"),
17+
title: control.buildTextOrWidget("title"),
18+
message: control.buildTextOrWidget("message"),
1919
cancelButton: control.buildWidget("cancel"),
2020
actions: control.buildWidgets("actions"),
2121
);

packages/flet/lib/src/controls/cupertino_list_tile.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ class CupertinoListTileControl extends StatelessWidget {
2020
Widget build(BuildContext context) {
2121
debugPrint("CupertinoListTile build: ${control.id}");
2222

23-
var title = control.buildWidget("title");
23+
var title = control.buildTextOrWidget("title");
2424
if (title == null) {
2525
return const ErrorControl(
2626
"CupertinoListTile.title must be provided and visible");
2727
}
28-
var leading = control.buildWidget("leading");
29-
var additionalInfo = control.buildWidget("additional_info");
30-
var subtitle = control.buildWidget("subtitle");
31-
var trailing = control.buildWidget("trailing");
28+
var leading = control.buildIconOrWidget("leading");
29+
var additionalInfo = control.buildTextOrWidget("additional_info");
30+
var subtitle = control.buildTextOrWidget("subtitle");
31+
var trailing = control.buildIconOrWidget("trailing");
3232
var backgroundColor = control.getColor("bgcolor", context);
3333
var bgcolorActivated = control.getColor("bgcolor_activated", context);
3434
var padding = control.getPadding("content_padding");
Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from typing import List, Optional
1+
from typing import Optional
22

33
from flet.controls.base_control import control
44
from flet.controls.constrained_control import ConstrainedControl
55
from flet.controls.control import Control
6+
from flet.controls.types import StrOrControl
67

78
__all__ = ["CupertinoActionSheet"]
89

@@ -12,12 +13,37 @@ class CupertinoActionSheet(ConstrainedControl):
1213
"""
1314
An iOS-style action sheet.
1415
15-
-----
16-
1716
Online docs: https://flet.dev/docs/controls/cupertinoactionsheet
1817
"""
1918

20-
title: Optional[Control] = None
21-
message: Optional[Control] = None
22-
actions: Optional[List[Control]] = None
19+
title: Optional[StrOrControl] = None
20+
"""
21+
A control containing the title of the action sheet.
22+
23+
Typically a [`Text`](https://flet.dev/docs/controls/text) control.
24+
"""
25+
26+
message: Optional[StrOrControl] = None
27+
"""
28+
A control containing a descriptive message that provides more details about the
29+
reason for the alert.
30+
31+
Typically a [`Text`](https://flet.dev/docs/controls/text) control.
32+
"""
33+
34+
actions: Optional[list[Control]] = None
35+
"""
36+
A list of action buttons to be shown in the sheet.
37+
38+
These actions are typically [`CupertinoActionSheetAction`](https://flet.dev/docs/controls/cupertinoactionsheetaction)s.
39+
40+
This list must have at least one action.
41+
"""
42+
2343
cancel: Optional[Control] = None
44+
"""
45+
An optional control to be shown below the actions but grouped separately from them.
46+
47+
Typically a [`CupertinoActionSheetAction`](https://flet.dev/docs/controls/cupertinoactionsheetaction)
48+
button.
49+
"""

sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_action_sheet_action.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,39 @@ class CupertinoActionSheetAction(ConstrainedControl):
1212
"""
1313
An action button typically used in a CupertinoActionSheet.
1414
15-
-----
16-
1715
Online docs: https://flet.dev/docs/controls/cupertinoactionsheetaction
1816
"""
1917

2018
content: StrOrControl
19+
"""
20+
The child control to be shown in this action button.
21+
22+
In case both `text` and `content` are provided, then `content` will be used.
23+
"""
24+
2125
default: bool = False
26+
"""
27+
Whether this action should receive the style of an emphasized, default action.
28+
29+
Defaults to `False`.
30+
"""
31+
2232
destructive: bool = False
33+
"""
34+
Whether this action should receive the style of a destructive action.
35+
36+
Defaults to `False`.
37+
"""
38+
2339
mouse_cursor: Optional[MouseCursor] = None
40+
"""
41+
TBD
42+
"""
43+
2444
on_click: OptionalControlEventCallable = None
45+
"""
46+
Fires when this action button is clicked.
47+
"""
2548

2649
def before_update(self):
2750
super().before_update()

sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_activity_indicator.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ class CupertinoActivityIndicator(ConstrainedControl):
1010
"""
1111
An iOS-style activity indicator that spins clockwise.
1212
13-
-----
14-
1513
Online docs: https://flet.dev/docs/controls/cupertinoactivityindicator
1614
"""
1715

1816
radius: Number = 10
17+
"""
18+
The radius of the activity indicator.
19+
"""
20+
1921
color: OptionalColorValue = None
22+
"""
23+
Defines the [color](https://flet.dev/docs/reference/colors) of the activity
24+
indicator.
25+
"""
26+
2027
animating: bool = True
28+
"""
29+
Whether the activity indicator is running its animation.
30+
"""
Lines changed: 42 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from dataclasses import field
2-
from typing import List, Optional
2+
from typing import Optional
33

44
from flet.controls.animation import Animation, AnimationCurve
55
from flet.controls.base_control import control
66
from flet.controls.control import Control
77
from flet.controls.dialog_control import DialogControl
8-
98
from flet.controls.duration import Duration
10-
119
from flet.controls.types import StrOrControl
1210

1311
__all__ = ["CupertinoAlertDialog"]
@@ -17,97 +15,64 @@
1715
class CupertinoAlertDialog(DialogControl):
1816
"""
1917
An iOS-style alert dialog.
20-
An alert dialog informs the user about situations that require acknowledgement. An alert dialog has an optional title and an optional list of actions. The title is displayed above the content and the actions are displayed below the content.
21-
22-
Example:
23-
```
24-
import flet as ft
25-
26-
27-
def main(page: ft.Page):
28-
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
29-
page.scroll = True
30-
31-
def handle_action_click(e):
32-
page.add(ft.Text(f"Action clicked: {e.control.text}"))
33-
# e.control is the clicked action button, e.control.parent is the corresponding parent dialog of the button
34-
page.close(e.control.parent)
35-
36-
cupertino_actions = [
37-
ft.CupertinoDialogAction(
38-
"Yes",
39-
is_destructive_action=True,
40-
on_click=handle_action_click,
41-
),
42-
ft.CupertinoDialogAction(
43-
text="No",
44-
is_default_action=False,
45-
on_click=handle_action_click,
46-
),
47-
]
48-
49-
material_actions = [
50-
ft.TextButton(text="Yes", on_click=handle_action_click),
51-
ft.TextButton(text="No", on_click=handle_action_click),
52-
]
53-
54-
page.add(
55-
ft.FilledButton(
56-
text="Open Material Dialog",
57-
on_click=lambda e: page.open(
58-
ft.AlertDialog(
59-
title=ft.Text("Material Alert Dialog"),
60-
content=ft.Text("Do you want to delete this file?"),
61-
actions=material_actions,
62-
)
63-
),
64-
),
65-
ft.CupertinoFilledButton(
66-
text="Open Cupertino Dialog",
67-
on_click=lambda e: page.open(
68-
ft.CupertinoAlertDialog(
69-
title=ft.Text("Cupertino Alert Dialog"),
70-
content=ft.Text("Do you want to delete this file?"),
71-
actions=cupertino_actions,
72-
)
73-
),
74-
),
75-
ft.FilledButton(
76-
text="Open Adaptive Dialog",
77-
adaptive=True,
78-
on_click=lambda e: page.open(
79-
ft.AlertDialog(
80-
adaptive=True,
81-
title=ft.Text("Adaptive Alert Dialog"),
82-
content=ft.Text("Do you want to delete this file?"),
83-
actions=cupertino_actions if page.platform in [ft.PagePlatform.IOS, ft.PagePlatform.MACOS] else material_actions,
84-
)
85-
),
86-
),
87-
)
8818
89-
90-
ft.app(target=main)
91-
```
92-
-----
19+
An alert dialog informs the user about situations that require acknowledgement. An
20+
alert dialog has an optional title and an optional list of actions. The title is
21+
displayed above the content and the actions are displayed below the content.
9322
9423
Online docs: https://flet.dev/docs/controls/cupertinoalertdialog
9524
"""
9625

9726
modal: bool = False
27+
"""
28+
If set to True, dialog cannot be dismissed by clicking the area outside of it.
29+
The default value is False.
30+
"""
31+
9832
title: Optional[StrOrControl] = None
33+
"""
34+
The (optional) title of the dialog is displayed in a large font at the top of the
35+
dialog.
36+
37+
Typically a [`Text`](https://flet.dev/docs/controls/text) control.
38+
"""
39+
9940
content: Optional[Control] = None
100-
actions: List[Control] = field(default_factory=list)
41+
"""
42+
The (optional) content of the dialog is displayed in the center of the dialog in a
43+
lighter font.
44+
45+
Typically this is a [`Column`](https://flet.dev/docs/controls/column) that contains
46+
the dialog's [`Text`](https://flet.dev/docs/controls/text) message.
47+
"""
48+
49+
actions: list[Control] = field(default_factory=list)
50+
"""
51+
The (optional) set of actions that are displayed at the bottom of the dialog.
52+
53+
Typically this is a list of
54+
[`CupertinoDialogAction`](https://flet.dev/docs/controls/cupertinodialogaction)
55+
controls.
56+
"""
57+
10158
inset_animation: Animation = field(
10259
default_factory=lambda: Animation(
10360
curve=AnimationCurve.DECELERATE, duration=Duration(milliseconds=100)
10461
)
10562
)
63+
"""
64+
The animation style to be used when the system keyboard intrudes into the space
65+
that the dialog is placed in.
66+
67+
Value is of type
68+
[`AnimationStyle`](https://flet.dev/docs/reference/types/animationstyle).
69+
"""
10670

10771
def before_update(self):
10872
super().before_update()
10973
assert (
11074
(isinstance(self.title, str) or self.title.visible)
11175
or (self.content and self.content.visible)
11276
or any(a.visible for a in self.actions)
113-
), "AlertDialog has nothing to display. Provide at minimum one of the following: title, content, actions"
77+
), "AlertDialog has nothing to display. Provide at minimum one of the "
78+
"following: title, content, actions"

0 commit comments

Comments
 (0)