Skip to content

Commit 290c6b4

Browse files
authored
Inesa/v1 docstrings for material controls (#5290)
* removed example * NavigationRailDestination * NavigationRail * removed example * Update outlined_button.py * PopupMenuButton docstrings and removed text property * ProgressBar docstrings * deleted example * ProgressRing properties * removed example * RadioGroup docstrings * removed example * Radio docstrings * asserts for RangeSlider * RangeSlider docstrings * Control docstring * ReorderableListView docstrings * SearchBar Control docstrings * SearchBar docstrings * formatted for ruf * asserts for SegmentedButton * SegmentedButton docstrings * SelectionArea docstrings * removed example * Slider docstrings * removed example * SnackBar docstrings * SubmenuButton docstrings * Switch docstrings * Tab docstrings, fixed SegmentedButton * Tab docstrings * TextButton description * TextButton docstrings * InputFilter docstrings * TextField description * TextField docstrings * FormFieldControl docstrings * TimePicker description * TimePicker docstrings * Tooltip description * Tooltip docstrings * TextField docstrings * VerticalDivider docstrings * AlertDialog docstrings formatting * docstrings for all Material Controls formatted
1 parent 03035c7 commit 290c6b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3324
-936
lines changed

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import '../utils/box.dart';
88
import '../utils/buttons.dart';
99
import '../utils/colors.dart';
1010
import '../utils/edge_insets.dart';
11-
import '../utils/icons.dart';
1211
import '../utils/misc.dart';
1312
import '../utils/mouse.dart';
1413
import '../utils/numbers.dart';
@@ -23,7 +22,7 @@ class PopupMenuButtonControl extends StatelessWidget {
2322
Widget build(BuildContext context) {
2423
debugPrint("PopupMenuButton build: ${control.id}");
2524

26-
var content = control.buildWidget("content");
25+
var content = control.buildTextOrWidget("content");
2726

2827
var popupMenuButton = PopupMenuButton<String>(
2928
enabled: !control.disabled,
@@ -57,27 +56,24 @@ class PopupMenuButtonControl extends StatelessWidget {
5756
.children("items")
5857
.where((i) => i.type == "PopupMenuItem")
5958
.map((item) {
60-
var itemIcon = item.getIcon("icon");
61-
var text = item.getString("text", "")!;
6259
var checked = item.getBool("checked");
6360
var height = item.getDouble("height", 48.0)!;
6461
var padding = item.getPadding("padding");
65-
var content = item.buildWidget("content");
62+
var itemContent = item.buildTextOrWidget("content");
63+
var itemIcon = item.buildIconOrWidget("icon");
6664
var mouseCursor = item.getMouseCursor("mouse_cursor");
6765

6866
Widget? child;
69-
if (content != null) {
70-
// custom content
71-
child = content;
72-
} else if (itemIcon != null && text != "") {
73-
// icon and text
67+
if (itemContent != null && itemIcon == null) {
68+
child = itemContent;
69+
} else if (itemContent == null && itemIcon != null) {
70+
child = itemIcon;
71+
} else if (itemContent != null && itemIcon != null) {
7472
child = Row(children: [
75-
Icon(itemIcon),
73+
itemIcon,
7674
const SizedBox(width: 8),
77-
Text(text)
75+
itemContent
7876
]);
79-
} else if (text != "") {
80-
child = Text(text);
8177
}
8278

8379
var result = checked != null

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ class _SegmentedButtonControlState extends State<SegmentedButtonControl>
9494
value: segment.getString("value")!,
9595
enabled: !segment.disabled,
9696
tooltip: segment.disabled ? null : segment.getString("tooltip"),
97-
icon: segment.buildWidget("icon"),
98-
label: segment.buildWidget("label"));
97+
icon: segment.buildIconOrWidget("icon"),
98+
label: segment.buildTextOrWidget("label"));
9999
}).toList());
100100

101101
return ConstrainedControl(control: widget.control, child: segmentedButton);

sdk/python/packages/flet/src/flet/controls/material/alert_dialog.py

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from dataclasses import field
2-
from typing import List, Optional
2+
from typing import Optional
33

44
from flet.controls.alignment import Alignment
55
from flet.controls.base_control import control
@@ -22,14 +22,18 @@
2222
@control("AlertDialog")
2323
class AlertDialog(DialogControl):
2424
"""
25-
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.
25+
An alert dialog informs the user about situations that require acknowledgement. An
26+
alert dialog has an optional title and an optional list of actions. The title is
27+
displayed above the content and the actions are displayed below the content.
2628
2729
Online docs: https://flet.dev/docs/controls/alertdialog
2830
"""
2931

3032
content: Optional[Control] = None
3133
"""
32-
The (optional) content of the dialog is displayed in the center of the dialog in a lighter font. Typically this is a [`Column`](https://flet.dev/docs/controls/column) that contains the dialog's [`Text`](https://flet.dev/docs/controls/text) message.
34+
The (optional) content of the dialog is displayed in the center of the dialog in a
35+
lighter font. Typically this is a [`Column`](https://flet.dev/docs/controls/column)
36+
that contains the dialog's [`Text`](https://flet.dev/docs/controls/text) message.
3337
3438
Value is of type `Control`.
3539
"""
@@ -43,21 +47,24 @@ class AlertDialog(DialogControl):
4347

4448
title: Optional[StrOrControl] = None
4549
"""
46-
The (optional) title of the dialog is displayed in a large font at the top of the dialog.
50+
The (optional) title of the dialog is displayed in a large font at the top of the
51+
dialog.
4752
4853
Typically a [`Text`](https://flet.dev/docs/controls/text) control.
4954
"""
5055

51-
actions: List[Control] = field(default_factory=list)
56+
actions: list[Control] = field(default_factory=list)
5257
"""
5358
The (optional) set of actions that are displayed at the bottom of the dialog.
5459
55-
Typically this is a list of [`TextButton`](https://flet.dev/docs/controls/textbutton) controls.
60+
Typically this is a list of [`TextButton`](https://flet.dev/docs/controls/textbutton)
61+
controls.
5662
"""
5763

5864
bgcolor: OptionalColorValue = None
5965
"""
60-
The background [color](https://flet.dev/docs/reference/colors) of the dialog's surface.
66+
The background [color](https://flet.dev/docs/reference/colors) of the dialog's
67+
surface.
6168
"""
6269

6370
elevation: OptionalNumber = None
@@ -69,7 +76,8 @@ class AlertDialog(DialogControl):
6976

7077
icon: Optional[Control] = None
7178
"""
72-
A control that is displayed at the top of the dialog. Typically a [`Icon`](https://flet.dev/docs/controls/icon) control.
79+
A control that is displayed at the top of the dialog. Typically a [`Icon`](https://flet.dev/docs/controls/icon)
80+
control.
7381
"""
7482

7583
title_padding: OptionalPaddingValue = None
@@ -80,16 +88,20 @@ class AlertDialog(DialogControl):
8088
8189
Value is of type [`PaddingValue`](https://flet.dev/docs/reference/types/aliases#paddingvalue).
8290
83-
Defaults to providing `24` pixels on the top, left, and right of the title. If the `content` is not `None`, then no
84-
bottom padding is provided (but see [`content_padding`](https://flet.dev/docs/reference/types/aliases#paddingvalue)).
85-
If it is not set, then an extra `20` pixels of bottom padding is added to separate the title from the actions.
91+
Defaults to providing `24` pixels on the top, left, and right of the title. If the
92+
`content` is not `None`, then no bottom padding is provided (but see [`content_padding`](https://flet.dev/docs/reference/types/aliases#paddingvalue)).
93+
If it is not set, then an extra `20` pixels of bottom padding is added to separate
94+
the title from the actions.
8695
"""
8796

8897
content_padding: OptionalPaddingValue = None
8998
"""
9099
Padding around the content.
91100
92-
If there is no content, no padding will be provided. Otherwise, padding of 20 pixels is provided above the content to separate the content from the title, and padding of 24 pixels is provided on the left, right, and bottom to separate the content from the other edges of the dialog.
101+
If there is no content, no padding will be provided. Otherwise, padding of 20
102+
pixels is provided above the content to separate the content from the title, and
103+
padding of 24 pixels is provided on the left, right, and bottom to separate the
104+
content from the other edges of the dialog.
93105
94106
Value is of type [`PaddingValue`](https://flet.dev/docs/reference/types/aliases#paddingvalue).
95107
"""
@@ -98,9 +110,11 @@ class AlertDialog(DialogControl):
98110
"""
99111
Padding around the set of actions at the bottom of the dialog.
100112
101-
Typically used to provide padding to the button bar between the button bar and the edges of the dialog.
113+
Typically used to provide padding to the button bar between the button bar and the
114+
edges of the dialog.
102115
103-
If are no actions, then no padding will be included. The padding around the button bar defaults to zero.
116+
If are no actions, then no padding will be included. The padding around the button
117+
bar defaults to zero.
104118
105119
Value is of type [`PaddingValue`](https://flet.dev/docs/reference/types/aliases#paddingvalue).
106120
"""
@@ -109,15 +123,16 @@ class AlertDialog(DialogControl):
109123
"""
110124
Defines the horizontal layout of the actions.
111125
112-
Value is of type [`MainAxisAlignment`](https://flet.dev/docs/reference/types/mainaxisalignment) and defaults to `MainAxisAlignment.END`.
126+
Value is of type [`MainAxisAlignment`](https://flet.dev/docs/reference/types/mainaxisalignment)
127+
and defaults to `MainAxisAlignment.END`.
113128
"""
114129

115130
shape: Optional[OutlinedBorder] = None
116131
"""
117132
The shape of the dialog.
118133
119-
Value is of type [`OutlinedBorder`](https://flet.dev/docs/reference/types/outlinedborder) and defaults
120-
to `RoundedRectangleBorder(radius=4.0)`.
134+
Value is of type [`OutlinedBorder`](https://flet.dev/docs/reference/types/outlinedborder)
135+
and defaults to `RoundedRectangleBorder(radius=4.0)`.
121136
"""
122137

123138
inset_padding: OptionalPaddingValue = None
@@ -126,8 +141,8 @@ class AlertDialog(DialogControl):
126141
127142
Value is of type [`PaddingValue`](https://flet.dev/docs/reference/types/aliases#paddingvalue).
128143
129-
Defaults to `padding.symmetric(vertical=40, horizontal=24)` - 40 pixels horizontally and 24 pixels vertically outside of
130-
the dialog box.
144+
Defaults to `padding.symmetric(vertical=40, horizontal=24)` - 40 pixels
145+
horizontally and 24 pixels vertically outside of the dialog box.
131146
"""
132147

133148
icon_padding: OptionalPaddingValue = None
@@ -146,13 +161,14 @@ class AlertDialog(DialogControl):
146161

147162
surface_tint_color: OptionalColorValue = None
148163
"""
149-
The [color](https://flet.dev/docs/reference/colors) used as a surface tint overlay on the dialog's background color, which reflects the
150-
dialog's elevation.
164+
The [color](https://flet.dev/docs/reference/colors) used as a surface tint overlay
165+
on the dialog's background color, which reflects the dialog's elevation.
151166
"""
152167

153168
shadow_color: OptionalColorValue = None
154169
"""
155-
The [color](https://flet.dev/docs/reference/colors) used to paint a drop shadow under the dialog, which reflects the dialog's elevation.
170+
The [color](https://flet.dev/docs/reference/colors) used to paint a drop shadow
171+
under the dialog, which reflects the dialog's elevation.
156172
"""
157173

158174
icon_color: OptionalColorValue = None
@@ -189,28 +205,33 @@ class AlertDialog(DialogControl):
189205
"""
190206
Controls how the contents of the dialog are clipped (or not) to the given `shape`.
191207
192-
Value is of type [`ClipBehavior`](https://flet.dev/docs/reference/types/clipbehavior) and defaults to `ClipBehavior.NONE`.
208+
Value is of type [`ClipBehavior`](https://flet.dev/docs/reference/types/clipbehavior)
209+
and defaults to `ClipBehavior.NONE`.
193210
"""
194211

195212
semantics_label: Optional[str] = None
196213
"""
197-
The semantic label of the dialog used by accessibility frameworks to announce screen transitions when the dialog is opened and closed.
214+
The semantic label of the dialog used by accessibility frameworks to announce
215+
screen transitions when the dialog is opened and closed.
198216
199-
In iOS, if this label is not provided, a semantic label will be inferred from the `title` if it is not null.
217+
In iOS, if this label is not provided, a semantic label will be inferred from the
218+
`title` if it is not null.
200219
201220
Value is of type `str`.
202221
"""
203222

204223
barrier_color: OptionalColorValue = None
205224
"""
206-
The [color](https://flet.dev/docs/reference/colors) of the modal barrier that darkens everything below the dialog.
225+
The [color](https://flet.dev/docs/reference/colors) of the modal barrier that
226+
darkens everything below the dialog.
207227
208-
If `None`, the [`DialogTheme.barrier_color`](https://flet.dev/docs/reference/types/dialogtheme#barrier_color) is used.
209-
If it is also `None`, then `Colors.BLACK_54` is used.
228+
If `None`, the [`DialogTheme.barrier_color`](https://flet.dev/docs/reference/types/dialogtheme#barrier_color)
229+
is used. If it is also `None`, then `Colors.BLACK_54` is used.
210230
"""
211231

212232
def before_update(self):
213233
super().before_update()
214234
assert (
215235
self.title or self.content or self.actions
216-
), "AlertDialog has nothing to display. Provide at minimum one of the following: title, content, actions"
236+
), "AlertDialog has nothing to display. Provide at minimum one of the "
237+
"following: title, content, actions"

0 commit comments

Comments
 (0)