Skip to main content

CupertinoSheet

An iOS-style sheet that slides up from the bottom of the screen and stops below its top edge.

While it is open, the page behind it moves down and shrinks, so this sheet looks stacked on top of the page. The user closes it by dragging it down.

Open it with BasePage.show_dialog and close it with BasePage.pop_dialog.

Example:

sheet = ft.CupertinoSheet(
show_drag_handle=True,
content=ft.Column(
controls=[
ft.Text("Sheet content"),
ft.CupertinoButton("Close", on_click=lambda _: page.pop_dialog()),
],
),
)
page.show_dialog(sheet)
CupertinoSheet
CupertinoSheet

Inherits: DialogControl

Properties

  • bgcolor - The background color of this sheet.
  • content - The control to be displayed in this sheet.
  • enable_drag - Whether the user can close this sheet by dragging it down.
  • has_platform_views - Whether this sheet, or the page behind it, shows a native platform view, such as a WebView or an ad.
  • open
  • show_drag_handle - Whether to show a drag handle at the top of this sheet.
  • top_gap - The gap between the top of the screen and the top of this sheet, as a fraction of the screen height.

Examples​

CupertinoSheet​

Opens a sheet with a [drag handle][flet.CupertinoSheet.show_drag_handle] using show_dialog(). Drag it down or tap Close to dismiss it; each on_dismiss adds a line to the page.

Sourceplay_arrowTry Online
import flet as ft


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

messages = ft.Column(tight=True)

def handle_sheet_dismissal(e: ft.Event[ft.DialogControl]):
messages.controls.append(ft.Text("Sheet dismissed"))
messages.update()

sheet = ft.CupertinoSheet(
show_drag_handle=True,
on_dismiss=handle_sheet_dismissal,
content=ft.SafeArea(
content=ft.Container(
padding=ft.Padding.all(20),
content=ft.Column(
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
controls=[
ft.Text("Cupertino sheet", size=20, weight=ft.FontWeight.BOLD),
ft.Text("Drag the sheet down or tap Close to dismiss it."),
ft.CupertinoButton(
on_click=lambda: page.pop_dialog(),
content="Close",
),
],
),
),
),
)

page.add(
ft.SafeArea(
content=ft.Column(
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
controls=[
ft.CupertinoFilledButton(
on_click=lambda: page.show_dialog(sheet),
content="Open CupertinoSheet",
),
messages,
],
),
)
)


if __name__ == "__main__":
ft.run(main)

Stacked CupertinoSheets​

Each sheet can open another one on top of it. The sheet below shrinks back, so the sheets look stacked, and Close removes only the top one with pop_dialog().

Sourceplay_arrowTry Online
import flet as ft


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

def open_sheet(level: int):
page.show_dialog(
ft.CupertinoSheet(
content=ft.SafeArea(
content=ft.Column(
expand=True,
alignment=ft.MainAxisAlignment.CENTER,
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
controls=[
ft.Text(
f"Sheet {level}", size=24, weight=ft.FontWeight.BOLD
),
ft.Text(
"Each new sheet stacks on top of the previous one."
),
ft.CupertinoFilledButton(
content="Open another sheet",
on_click=lambda: open_sheet(level + 1),
),
ft.CupertinoButton(
content="Close",
on_click=lambda: page.pop_dialog(),
),
],
)
)
)
)

page.add(
ft.CupertinoFilledButton(content="Open sheet", on_click=lambda: open_sheet(1))
)


if __name__ == "__main__":
ft.run(main)

CupertinoSheet picker​

Uses a sheet as a picker. A Pagelet gives it a CupertinoAppBar with a Cancel button above a scrollable list of cities. Tapping a city shows it on the page and closes the sheet.

Sourceplay_arrowTry Online
import flet as ft

CITIES = [
"Amsterdam",
"Berlin",
"Buenos Aires",
"Cairo",
"Douala",
"Istanbul",
"Lagos",
"Lisbon",
"London",
"Nairobi",
"New York",
"Paris",
"Rome",
"Seoul",
"Tokyo",
"Yaoundé",
]


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

def handle_city_click(e: ft.Event[ft.CupertinoListTile]):
selection.value = f"Selected city: {e.control.data}"
selection.update()
page.pop_dialog()

sheet = ft.CupertinoSheet(
content=ft.Pagelet(
appbar=ft.CupertinoAppBar(
title=ft.Text("Choose a city"),
leading=ft.CupertinoButton(
content="Cancel",
padding=0,
on_click=lambda: page.pop_dialog(),
),
automatically_imply_leading=False,
),
content=ft.ListView(
controls=[
ft.CupertinoListTile(
title=city,
data=city,
on_click=handle_city_click,
)
for city in CITIES
],
),
),
)

page.add(
selection := ft.Text("No city selected"),
ft.CupertinoFilledButton(
content="Choose a city",
on_click=lambda: page.show_dialog(sheet),
),
)


if __name__ == "__main__":
ft.run(main)

Properties​

bgcolorclass-attributeinstance-attribute​

bgcolor: ColorValue | None = None

The background color of this sheet.

Defaults to CupertinoColors.SYSTEM_BACKGROUND.

contentinstance-attribute​

content: Control

The control to be displayed in this sheet.

Note

With touch input, dragging a scrollable control in it, such as ListView, scrolls that control instead of closing this sheet. Dragging a part that doesn't scroll, or dragging with a mouse, closes it.

enable_dragclass-attributeinstance-attribute​

enable_drag: bool = True

Whether the user can close this sheet by dragging it down.

A change applies the next time this sheet opens.

has_platform_viewsclass-attributeinstance-attribute​

has_platform_views: bool = False

Whether this sheet, or the page behind it, shows a native platform view, such as a WebView or an ad.

Set it to True when it does on iOS and macOS, or when it shows an ad on Android, so the native view moves with the rest of the page while this sheet opens and closes.

A change applies the next time this sheet opens.

openclass-attributeinstance-attribute​

open: bool = field(default=False, kw_only=True)

show_drag_handleclass-attributeinstance-attribute​

show_drag_handle: bool = False

Whether to show a drag handle at the top of this sheet.

The handle is drawn over the top of content; a SafeArea in content keeps its content below it.

A change applies the next time this sheet opens.

top_gapclass-attributeinstance-attribute​

top_gap: Number | None = None

The gap between the top of the screen and the top of this sheet, as a fraction of the screen height.

For example, 0.0 makes this sheet reach the top of the screen and 0.9 makes it cover only the bottom 10% of the screen. If None, the gap is 0.08.

A change applies the next time this sheet opens.

Note

When it is set, the page behind this sheet keeps its size and position.

Raises:

  • ValueError - If it is not between 0.0 and 0.9, inclusive.