Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/flet/lib/src/controls/dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class _DropdownControlState extends State<DropdownControl> {
helperText: widget.control.getString("helper_text"),
menuStyle: menuStyle,
inputDecorationTheme: inputDecorationTheme,
inputFormatters: inputFormatters.isEmpty ? null : inputFormatters,
onSelected: widget.control.disabled
? null
: (String? selection) {
Expand All @@ -291,7 +292,6 @@ class _DropdownControlState extends State<DropdownControl> {
);

var didAutoFocus = false;

if (!didAutoFocus && autofocus) {
didAutoFocus = true;
SchedulerBinding.instance.addPostFrameCallback((_) {
Expand Down
23 changes: 17 additions & 6 deletions packages/flet/lib/src/controls/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ class _PageControlState extends State<PageControl> with WidgetsBindingObserver {
var appStatus = context
.select<FletBackend, ({bool isLoading, String error})>((backend) =>
(isLoading: backend.isLoading, error: backend.error));
var appStartupScreenMessage =
backend.appStartupScreenMessage ?? "";
var appStartupScreenMessage = backend.appStartupScreenMessage ?? "";
var formattedErrorMessage =
backend.formatAppErrorMessage(appStatus.error);

Expand Down Expand Up @@ -432,6 +431,18 @@ class _PageControlState extends State<PageControl> with WidgetsBindingObserver {
? control.getCupertinoTheme("dark_theme", context, Brightness.dark)
: control.getCupertinoTheme("theme", context, Brightness.dark);

var materialTheme = themeMode == ThemeMode.dark ||
((themeMode == null || themeMode == ThemeMode.system) &&
brightness == Brightness.dark)
? darkTheme
: lightTheme;

Widget scaffoldMessengerBuilder(BuildContext context, Widget? child) {
return Theme(
data: materialTheme ?? lightTheme ?? ThemeData(),
child: ScaffoldMessenger(child: child ?? const SizedBox.shrink()));
}

var showSemanticsDebugger =
control.getBool("show_semantics_debugger", false)!;

Expand All @@ -442,6 +453,7 @@ class _PageControlState extends State<PageControl> with WidgetsBindingObserver {
showSemanticsDebugger: showSemanticsDebugger,
title: windowTitle,
theme: cupertinoTheme,
builder: scaffoldMessengerBuilder,
supportedLocales: localeConfiguration.supportedLocales,
locale: localeConfiguration.locale,
localizationsDelegates: localizationsDelegates,
Expand All @@ -454,6 +466,7 @@ class _PageControlState extends State<PageControl> with WidgetsBindingObserver {
routeInformationParser: _routeParser,
title: windowTitle,
theme: cupertinoTheme,
builder: scaffoldMessengerBuilder,
localizationsDelegates: localizationsDelegates,
supportedLocales: localeConfiguration.supportedLocales,
locale: localeConfiguration.locale,
Expand Down Expand Up @@ -503,14 +516,12 @@ class _PageControlState extends State<PageControl> with WidgetsBindingObserver {

var backend = FletBackend.of(context);
var showAppStartupScreen = backend.showAppStartupScreen ?? false;
var appStartupScreenMessage =
backend.appStartupScreenMessage ?? "";
var appStartupScreenMessage = backend.appStartupScreenMessage ?? "";

var appStatus =
context.select<FletBackend, ({bool isLoading, String error})>(
(backend) => (isLoading: backend.isLoading, error: backend.error));
var formattedErrorMessage =
backend.formatAppErrorMessage(appStatus.error);
var formattedErrorMessage = backend.formatAppErrorMessage(appStatus.error);

var views = widget.control.children("views");
List<Page<dynamic>> pages = [];
Expand Down
Empty file.
32 changes: 14 additions & 18 deletions sdk/python/examples/controls/pagelet/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,28 @@


def main(page: ft.Page):
page.horizontal_alignment = ft.MainAxisAlignment.CENTER
page.vertical_alignment = ft.CrossAxisAlignment.CENTER

async def handle_show_drawer(e: ft.Event[ft.FloatingActionButton]):
await pagelet.show_drawer()

async def handle_show_end_drawer():
async def handle_show_end_drawer(e: ft.Event[ft.Button]):
await pagelet.show_end_drawer()
await asyncio.sleep(3)
await pagelet.close_end_drawer()

page.add(
pagelet := ft.Pagelet(
width=400,
height=400,
width=500,
height=500,
appbar=ft.AppBar(
title=ft.Text("Pagelet AppBar Title"),
bgcolor=ft.Colors.AMBER_ACCENT,
),
content=ft.Container(
ft.Column(
[
ft.Text("Pagelet Body"),
ft.Button("Show end drawer", on_click=handle_show_end_drawer),
]
),
padding=ft.Padding.all(16),
title=ft.Text("Pagelet AppBar"),
center_title=True,
bgcolor=ft.Colors.RED_500,
),
bgcolor=ft.Colors.AMBER_100,
content=ft.Text("Pagelet Body"),
bgcolor=ft.Colors.SURFACE_CONTAINER_HIGHEST,
bottom_appbar=ft.BottomAppBar(
bgcolor=ft.Colors.BLUE,
shape=ft.CircularRectangleNotchShape(),
Expand Down Expand Up @@ -71,13 +67,13 @@ async def handle_show_end_drawer():
],
),
floating_action_button=ft.FloatingActionButton(
content="Open",
icon=ft.Icons.ADD,
shape=ft.CircleBorder(),
on_click=handle_show_drawer,
),
floating_action_button_location=ft.FloatingActionButtonLocation.CENTER_DOCKED,
)
)


ft.run(main)
if __name__ == "__main__":
ft.run(main)
Binary file not shown.
41 changes: 33 additions & 8 deletions sdk/python/examples/controls/responsive_row/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,59 @@ def handle_page_resize(e: ft.PageResizeEvent):
content=ft.Text("Column 1"),
padding=5,
bgcolor=ft.Colors.YELLOW,
col={"xs": 12, "md": 6, "lg": 3},
col={
ft.ResponsiveRowBreakpoint.XS: 12,
ft.ResponsiveRowBreakpoint.MD: 6,
ft.ResponsiveRowBreakpoint.LG: 3,
},
),
ft.Container(
content=ft.Text("Column 2"),
padding=5,
bgcolor=ft.Colors.GREEN,
col={"xs": 12, "md": 6, "lg": 3},
col={
ft.ResponsiveRowBreakpoint.XS: 12,
ft.ResponsiveRowBreakpoint.MD: 6,
ft.ResponsiveRowBreakpoint.LG: 3,
},
),
ft.Container(
content=ft.Text("Column 3"),
padding=5,
bgcolor=ft.Colors.BLUE,
col={"xs": 12, "md": 6, "lg": 3},
col={
ft.ResponsiveRowBreakpoint.XS: 12,
ft.ResponsiveRowBreakpoint.MD: 6,
ft.ResponsiveRowBreakpoint.LG: 3,
},
),
ft.Container(
content=ft.Text("Column 4"),
padding=5,
bgcolor=ft.Colors.PINK_300,
col={"xs": 12, "md": 6, "lg": 3},
col={
ft.ResponsiveRowBreakpoint.XS: 12,
ft.ResponsiveRowBreakpoint.MD: 6,
ft.ResponsiveRowBreakpoint.LG: 3,
},
),
],
),
ft.ResponsiveRow(
run_spacing={"xs": 10},
run_spacing={ft.ResponsiveRowBreakpoint.XS: 10},
controls=[
ft.TextField(label="TextField 1", col={"md": 4}),
ft.TextField(label="TextField 2", col={"md": 4}),
ft.TextField(label="TextField 3", col={"md": 4}),
ft.TextField(
label="TextField 1",
col={ft.ResponsiveRowBreakpoint.MD: 4},
),
ft.TextField(
label="TextField 2",
col={ft.ResponsiveRowBreakpoint.MD: 4},
),
ft.TextField(
label="TextField 3",
col={ft.ResponsiveRowBreakpoint.MD: 4},
),
],
),
pw,
Expand Down
102 changes: 102 additions & 0 deletions sdk/python/examples/controls/responsive_row/custom_breakpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import flet as ft


def main(page: ft.Page):
page.title = "ResponsiveRow with custom breakpoints"
page.padding = 16

breakpoints = {
"phone": 0,
"tablet": 640,
"desktop": 1000,
}

sorted_breakpoints = sorted(breakpoints.items(), key=lambda item: item[1])

breakpoint_labels = {
name: ft.Text(f"{name}: \u2265 {value}px", weight=ft.FontWeight.W_500)
for name, value in sorted_breakpoints
}

width_label = ft.Text()
breakpoint_label = ft.Text()

def update_status(_=None):
width = (
(page.window.width if page.window and page.window.width else None)
or page.width
or 0
)
width_label.value = f"Page width: {width:.0f}px"
active_breakpoint = max(
(bp for bp, min_width in breakpoints.items() if width >= min_width),
key=lambda bp: breakpoints[bp],
default="phone",
)
breakpoint_label.value = f"Active breakpoint: {active_breakpoint}"
for name, label in breakpoint_labels.items():
is_active = name == active_breakpoint
label.color = ft.Colors.BLUE_700 if is_active else None
label.weight = ft.FontWeight.W_700 if is_active else ft.FontWeight.W_400
label.update()
width_label.update()
breakpoint_label.update()

page.on_resize = update_status

page.add(
ft.Text("Resize the window to see custom breakpoints in action."),
ft.Text("Cards switch column spans at phone, tablet, and desktop widths."),
ft.Column(
[
ft.Text(
"Custom breakpoints (min widths):",
weight=ft.FontWeight.W_600,
),
ft.Column(list(breakpoint_labels.values()), spacing=2),
],
spacing=6,
),
ft.ResponsiveRow(
breakpoints=breakpoints,
columns={"phone": 4, "tablet": 8, "desktop": 12},
spacing=10,
run_spacing=10,
controls=[
ft.Container(
content=ft.Text("Card 1", size=16, weight=ft.FontWeight.W_600),
alignment=ft.Alignment.CENTER,
bgcolor=ft.Colors.AMBER_200,
height=90,
col={"phone": 4, "tablet": 4, "desktop": 3},
),
ft.Container(
content=ft.Text("Card 2", size=16, weight=ft.FontWeight.W_600),
alignment=ft.Alignment.CENTER,
bgcolor=ft.Colors.GREEN_200,
height=90,
col={"phone": 4, "tablet": 4, "desktop": 3},
),
ft.Container(
content=ft.Text("Card 3", size=16, weight=ft.FontWeight.W_600),
alignment=ft.Alignment.CENTER,
bgcolor=ft.Colors.BLUE_200,
height=90,
col={"phone": 4, "tablet": 4, "desktop": 3},
),
ft.Container(
content=ft.Text("Card 4", size=16, weight=ft.FontWeight.W_600),
alignment=ft.Alignment.CENTER,
bgcolor=ft.Colors.PINK_200,
height=90,
col={"phone": 4, "tablet": 4, "desktop": 3},
),
],
),
width_label,
breakpoint_label,
)
update_status()


ft.run(main)
2 changes: 1 addition & 1 deletion sdk/python/packages/flet/docs/controls/menubar.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ example_images: ../examples/controls/menu_bar/media
--8<-- "{{ examples }}/nested_submenus.py"
```

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


{{ class_members(class_name) }}
8 changes: 4 additions & 4 deletions sdk/python/packages/flet/docs/controls/pagelet.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
---
class_name: flet.Pagelet
examples: ../../examples/controls/pagelet
example_images: ../examples/controls/pagelet/media
example_images: ../test-images/examples/core/golden/macos/pagelet
---

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

## Examples

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

### Pagelet example
### Basic example

```python
--8<-- "{{ examples }}/basic.py"
```

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


{{ class_members(class_name) }}
7 changes: 7 additions & 0 deletions sdk/python/packages/flet/docs/controls/responsiverow.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ example_images: ../examples/controls/responsive_row/media
{{ image(example_images + "/basic.gif", alt="basic", width="80%") }}


### Custom breakpoints

```python
--8<-- "{{ examples }}/custom_breakpoint.py"
```


{{ class_members(class_name) }}
5 changes: 5 additions & 0 deletions sdk/python/packages/flet/docs/controls/segment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
class_name: flet.Segment
---

{{ class_all_options(class_name) }}
5 changes: 1 addition & 4 deletions sdk/python/packages/flet/docs/controls/segmentedbutton.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
class_name: flet.SegmentedButton
examples: ../../examples/controls/segmented_button
example_images: ../test-images/examples/material/golden/macos/segmented_button
segment_class_name: flet.Segment
---

{{ class_summary(class_name, example_images + "/image_for_docs.png", image_caption="Basic segmented button") }}
Expand All @@ -17,9 +16,7 @@ segment_class_name: flet.Segment
--8<-- "{{ examples }}/single_multiple_selection.py"
```

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


{{ class_members(class_name) }}

{{ class_all_options(segment_class_name) }}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading