Skip to content

Commit 77a1958

Browse files
authored
fix: SnackBar and Banner not opening in cupertino pages (#5848)
* Segment docs * Fix #2944: add ResponsiveRow custom breakpoint example * fix: host snack bars in adaptive cupertino page * add test for snackbar in adaptive cupertino page * update test image * fix #5370: add input formatters in dropdown * fix #5562: `Pagelet` integration tests
1 parent 7e91fc5 commit 77a1958

File tree

23 files changed

+314
-69
lines changed

23 files changed

+314
-69
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ class _DropdownControlState extends State<DropdownControl> {
280280
helperText: widget.control.getString("helper_text"),
281281
menuStyle: menuStyle,
282282
inputDecorationTheme: inputDecorationTheme,
283+
inputFormatters: inputFormatters.isEmpty ? null : inputFormatters,
283284
onSelected: widget.control.disabled
284285
? null
285286
: (String? selection) {
@@ -291,7 +292,6 @@ class _DropdownControlState extends State<DropdownControl> {
291292
);
292293

293294
var didAutoFocus = false;
294-
295295
if (!didAutoFocus && autofocus) {
296296
didAutoFocus = true;
297297
SchedulerBinding.instance.addPostFrameCallback((_) {

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ class _PageControlState extends State<PageControl> with WidgetsBindingObserver {
380380
var appStatus = context
381381
.select<FletBackend, ({bool isLoading, String error})>((backend) =>
382382
(isLoading: backend.isLoading, error: backend.error));
383-
var appStartupScreenMessage =
384-
backend.appStartupScreenMessage ?? "";
383+
var appStartupScreenMessage = backend.appStartupScreenMessage ?? "";
385384
var formattedErrorMessage =
386385
backend.formatAppErrorMessage(appStatus.error);
387386

@@ -471,6 +470,18 @@ class _PageControlState extends State<PageControl> with WidgetsBindingObserver {
471470
? control.getCupertinoTheme("dark_theme", context, Brightness.dark)
472471
: control.getCupertinoTheme("theme", context, Brightness.dark);
473472

473+
var materialTheme = themeMode == ThemeMode.dark ||
474+
((themeMode == null || themeMode == ThemeMode.system) &&
475+
brightness == Brightness.dark)
476+
? darkTheme
477+
: lightTheme;
478+
479+
Widget scaffoldMessengerBuilder(BuildContext context, Widget? child) {
480+
return Theme(
481+
data: materialTheme ?? lightTheme ?? ThemeData(),
482+
child: ScaffoldMessenger(child: child ?? const SizedBox.shrink()));
483+
}
484+
474485
var showSemanticsDebugger =
475486
control.getBool("show_semantics_debugger", false)!;
476487

@@ -481,6 +492,7 @@ class _PageControlState extends State<PageControl> with WidgetsBindingObserver {
481492
showSemanticsDebugger: showSemanticsDebugger,
482493
title: windowTitle,
483494
theme: cupertinoTheme,
495+
builder: scaffoldMessengerBuilder,
484496
supportedLocales: localeConfiguration.supportedLocales,
485497
locale: localeConfiguration.locale,
486498
localizationsDelegates: localizationsDelegates,
@@ -493,6 +505,7 @@ class _PageControlState extends State<PageControl> with WidgetsBindingObserver {
493505
routeInformationParser: _routeParser,
494506
title: windowTitle,
495507
theme: cupertinoTheme,
508+
builder: scaffoldMessengerBuilder,
496509
localizationsDelegates: localizationsDelegates,
497510
supportedLocales: localeConfiguration.supportedLocales,
498511
locale: localeConfiguration.locale,
@@ -542,14 +555,12 @@ class _PageControlState extends State<PageControl> with WidgetsBindingObserver {
542555

543556
var backend = FletBackend.of(context);
544557
var showAppStartupScreen = backend.showAppStartupScreen ?? false;
545-
var appStartupScreenMessage =
546-
backend.appStartupScreenMessage ?? "";
558+
var appStartupScreenMessage = backend.appStartupScreenMessage ?? "";
547559

548560
var appStatus =
549561
context.select<FletBackend, ({bool isLoading, String error})>(
550562
(backend) => (isLoading: backend.isLoading, error: backend.error));
551-
var formattedErrorMessage =
552-
backend.formatAppErrorMessage(appStatus.error);
563+
var formattedErrorMessage = backend.formatAppErrorMessage(appStatus.error);
553564

554565
var views = widget.control.children("views");
555566
List<Page<dynamic>> pages = [];

sdk/python/examples/controls/pagelet/__init__.py

Whitespace-only changes.

sdk/python/examples/controls/pagelet/basic.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,28 @@
44

55

66
def main(page: ft.Page):
7+
page.horizontal_alignment = ft.MainAxisAlignment.CENTER
8+
page.vertical_alignment = ft.CrossAxisAlignment.CENTER
9+
710
async def handle_show_drawer(e: ft.Event[ft.FloatingActionButton]):
811
await pagelet.show_drawer()
912

10-
async def handle_show_end_drawer():
13+
async def handle_show_end_drawer(e: ft.Event[ft.Button]):
1114
await pagelet.show_end_drawer()
1215
await asyncio.sleep(3)
1316
await pagelet.close_end_drawer()
1417

1518
page.add(
1619
pagelet := ft.Pagelet(
17-
width=400,
18-
height=400,
20+
width=500,
21+
height=500,
1922
appbar=ft.AppBar(
20-
title=ft.Text("Pagelet AppBar Title"),
21-
bgcolor=ft.Colors.AMBER_ACCENT,
22-
),
23-
content=ft.Container(
24-
ft.Column(
25-
[
26-
ft.Text("Pagelet Body"),
27-
ft.Button("Show end drawer", on_click=handle_show_end_drawer),
28-
]
29-
),
30-
padding=ft.Padding.all(16),
23+
title=ft.Text("Pagelet AppBar"),
24+
center_title=True,
25+
bgcolor=ft.Colors.RED_500,
3126
),
32-
bgcolor=ft.Colors.AMBER_100,
27+
content=ft.Text("Pagelet Body"),
28+
bgcolor=ft.Colors.SURFACE_CONTAINER_HIGHEST,
3329
bottom_appbar=ft.BottomAppBar(
3430
bgcolor=ft.Colors.BLUE,
3531
shape=ft.CircularRectangleNotchShape(),
@@ -71,13 +67,13 @@ async def handle_show_end_drawer():
7167
],
7268
),
7369
floating_action_button=ft.FloatingActionButton(
74-
content="Open",
70+
icon=ft.Icons.ADD,
7571
shape=ft.CircleBorder(),
76-
on_click=handle_show_drawer,
7772
),
7873
floating_action_button_location=ft.FloatingActionButtonLocation.CENTER_DOCKED,
7974
)
8075
)
8176

8277

83-
ft.run(main)
78+
if __name__ == "__main__":
79+
ft.run(main)
-223 KB
Binary file not shown.

sdk/python/examples/controls/responsive_row/basic.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,59 @@ def handle_page_resize(e: ft.PageResizeEvent):
1818
content=ft.Text("Column 1"),
1919
padding=5,
2020
bgcolor=ft.Colors.YELLOW,
21-
col={"xs": 12, "md": 6, "lg": 3},
21+
col={
22+
ft.ResponsiveRowBreakpoint.XS: 12,
23+
ft.ResponsiveRowBreakpoint.MD: 6,
24+
ft.ResponsiveRowBreakpoint.LG: 3,
25+
},
2226
),
2327
ft.Container(
2428
content=ft.Text("Column 2"),
2529
padding=5,
2630
bgcolor=ft.Colors.GREEN,
27-
col={"xs": 12, "md": 6, "lg": 3},
31+
col={
32+
ft.ResponsiveRowBreakpoint.XS: 12,
33+
ft.ResponsiveRowBreakpoint.MD: 6,
34+
ft.ResponsiveRowBreakpoint.LG: 3,
35+
},
2836
),
2937
ft.Container(
3038
content=ft.Text("Column 3"),
3139
padding=5,
3240
bgcolor=ft.Colors.BLUE,
33-
col={"xs": 12, "md": 6, "lg": 3},
41+
col={
42+
ft.ResponsiveRowBreakpoint.XS: 12,
43+
ft.ResponsiveRowBreakpoint.MD: 6,
44+
ft.ResponsiveRowBreakpoint.LG: 3,
45+
},
3446
),
3547
ft.Container(
3648
content=ft.Text("Column 4"),
3749
padding=5,
3850
bgcolor=ft.Colors.PINK_300,
39-
col={"xs": 12, "md": 6, "lg": 3},
51+
col={
52+
ft.ResponsiveRowBreakpoint.XS: 12,
53+
ft.ResponsiveRowBreakpoint.MD: 6,
54+
ft.ResponsiveRowBreakpoint.LG: 3,
55+
},
4056
),
4157
],
4258
),
4359
ft.ResponsiveRow(
44-
run_spacing={"xs": 10},
60+
run_spacing={ft.ResponsiveRowBreakpoint.XS: 10},
4561
controls=[
46-
ft.TextField(label="TextField 1", col={"md": 4}),
47-
ft.TextField(label="TextField 2", col={"md": 4}),
48-
ft.TextField(label="TextField 3", col={"md": 4}),
62+
ft.TextField(
63+
label="TextField 1",
64+
col={ft.ResponsiveRowBreakpoint.MD: 4},
65+
),
66+
ft.TextField(
67+
label="TextField 2",
68+
col={ft.ResponsiveRowBreakpoint.MD: 4},
69+
),
70+
ft.TextField(
71+
label="TextField 3",
72+
col={ft.ResponsiveRowBreakpoint.MD: 4},
73+
),
4974
],
5075
),
5176
pw,
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import flet as ft
2+
3+
4+
def main(page: ft.Page):
5+
page.title = "ResponsiveRow with custom breakpoints"
6+
page.padding = 16
7+
8+
breakpoints = {
9+
"phone": 0,
10+
"tablet": 640,
11+
"desktop": 1000,
12+
}
13+
14+
sorted_breakpoints = sorted(breakpoints.items(), key=lambda item: item[1])
15+
16+
breakpoint_labels = {
17+
name: ft.Text(f"{name}: \u2265 {value}px", weight=ft.FontWeight.W_500)
18+
for name, value in sorted_breakpoints
19+
}
20+
21+
width_label = ft.Text()
22+
breakpoint_label = ft.Text()
23+
24+
def update_status(_=None):
25+
width = (
26+
(page.window.width if page.window and page.window.width else None)
27+
or page.width
28+
or 0
29+
)
30+
width_label.value = f"Page width: {width:.0f}px"
31+
active_breakpoint = max(
32+
(bp for bp, min_width in breakpoints.items() if width >= min_width),
33+
key=lambda bp: breakpoints[bp],
34+
default="phone",
35+
)
36+
breakpoint_label.value = f"Active breakpoint: {active_breakpoint}"
37+
for name, label in breakpoint_labels.items():
38+
is_active = name == active_breakpoint
39+
label.color = ft.Colors.BLUE_700 if is_active else None
40+
label.weight = ft.FontWeight.W_700 if is_active else ft.FontWeight.W_400
41+
label.update()
42+
width_label.update()
43+
breakpoint_label.update()
44+
45+
page.on_resize = update_status
46+
47+
page.add(
48+
ft.Text("Resize the window to see custom breakpoints in action."),
49+
ft.Text("Cards switch column spans at phone, tablet, and desktop widths."),
50+
ft.Column(
51+
[
52+
ft.Text(
53+
"Custom breakpoints (min widths):",
54+
weight=ft.FontWeight.W_600,
55+
),
56+
ft.Column(list(breakpoint_labels.values()), spacing=2),
57+
],
58+
spacing=6,
59+
),
60+
ft.ResponsiveRow(
61+
breakpoints=breakpoints,
62+
columns={"phone": 4, "tablet": 8, "desktop": 12},
63+
spacing=10,
64+
run_spacing=10,
65+
controls=[
66+
ft.Container(
67+
content=ft.Text("Card 1", size=16, weight=ft.FontWeight.W_600),
68+
alignment=ft.Alignment.CENTER,
69+
bgcolor=ft.Colors.AMBER_200,
70+
height=90,
71+
col={"phone": 4, "tablet": 4, "desktop": 3},
72+
),
73+
ft.Container(
74+
content=ft.Text("Card 2", size=16, weight=ft.FontWeight.W_600),
75+
alignment=ft.Alignment.CENTER,
76+
bgcolor=ft.Colors.GREEN_200,
77+
height=90,
78+
col={"phone": 4, "tablet": 4, "desktop": 3},
79+
),
80+
ft.Container(
81+
content=ft.Text("Card 3", size=16, weight=ft.FontWeight.W_600),
82+
alignment=ft.Alignment.CENTER,
83+
bgcolor=ft.Colors.BLUE_200,
84+
height=90,
85+
col={"phone": 4, "tablet": 4, "desktop": 3},
86+
),
87+
ft.Container(
88+
content=ft.Text("Card 4", size=16, weight=ft.FontWeight.W_600),
89+
alignment=ft.Alignment.CENTER,
90+
bgcolor=ft.Colors.PINK_200,
91+
height=90,
92+
col={"phone": 4, "tablet": 4, "desktop": 3},
93+
),
94+
],
95+
),
96+
width_label,
97+
breakpoint_label,
98+
)
99+
update_status()
100+
101+
102+
ft.run(main)

sdk/python/packages/flet/docs/controls/menubar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ example_images: ../examples/controls/menu_bar/media
1616
--8<-- "{{ examples }}/nested_submenus.py"
1717
```
1818

19-
{{ image(example_images + "/nested_submenus.gif", alt="nested-submenus", width="80%") }}
19+
{{ image(example_images + "/nested_submenus.gif", width="80%") }}
2020

2121

2222
{{ class_members(class_name) }}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
---
22
class_name: flet.Pagelet
33
examples: ../../examples/controls/pagelet
4-
example_images: ../examples/controls/pagelet/media
4+
example_images: ../test-images/examples/core/golden/macos/pagelet
55
---
66

7-
{{ class_summary(class_name) }}
7+
{{ class_summary(class_name, example_images + "/image_for_docs.png", image_caption="Basic Pagelet") }}
88

99
## Examples
1010

1111
[Live example](https://flet-controls-gallery.fly.dev/layout/pagelet)
1212

13-
### Pagelet example
13+
### Basic example
1414

1515
```python
1616
--8<-- "{{ examples }}/basic.py"
1717
```
1818

19-
{{ image(example_images + "/basic.png", alt="basic", width="80%") }}
19+
{{ image(example_images + "/basic.png", width="80%") }}
2020

2121

2222
{{ class_members(class_name) }}

sdk/python/packages/flet/docs/controls/responsiverow.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ example_images: ../examples/controls/responsive_row/media
1919
{{ image(example_images + "/basic.gif", alt="basic", width="80%") }}
2020

2121

22+
### Custom breakpoints
23+
24+
```python
25+
--8<-- "{{ examples }}/custom_breakpoint.py"
26+
```
27+
28+
2229
{{ class_members(class_name) }}

0 commit comments

Comments
 (0)