Skip to content

CupertinoTimerPicker

A countdown timer picker in iOS style.

It can show a countdown duration with hour, minute and second spinners. The duration is bound between 0 and 23 hours 59 minutes 59 seconds.

Inherits: LayoutControl

Properties

Events

Examples#

Live example

Basic Example#

import time

import flet as ft


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

    timer_picker_value_ref = ft.Ref[ft.Text]()

    def handle_timer_picker_change(e: ft.Event[ft.CupertinoTimerPicker]):
        timer_picker_value_ref.current.value = time.strftime(
            "%H:%M:%S", time.gmtime(e.data.in_seconds)
        )
        # timer_picker_value_ref.current.value = f"{e.data.in_hours}:{(e.data.in_minutes % 60)}:{(e.data.in_seconds % 60) % 60}"
        page.update()

    timer_picker = ft.CupertinoTimerPicker(
        value=300,
        second_interval=10,
        minute_interval=1,
        mode=ft.CupertinoTimerPickerMode.HOUR_MINUTE_SECONDS,
        on_change=handle_timer_picker_change,
    )

    page.add(
        ft.Row(
            tight=True,
            controls=[
                ft.Text("TimerPicker Value:", size=23),
                ft.CupertinoButton(
                    content=ft.Text(
                        ref=timer_picker_value_ref,
                        value="00:01:10",
                        size=23,
                        color=ft.CupertinoColors.DESTRUCTIVE_RED,
                    ),
                    on_click=lambda e: page.show_dialog(
                        ft.CupertinoBottomSheet(
                            content=timer_picker,
                            height=216,
                            padding=ft.Padding.only(top=6),
                        )
                    ),
                ),
            ],
        ),
    )


ft.run(main)

basic

Properties#

alignment #

alignment: Alignment = field(default_factory=lambda: CENTER)

Defines how this picker should be positioned within its parent.

bgcolor #

bgcolor: ColorValue | None = None

The background color of this picker.

item_extent #

item_extent: Number = 32.0

The uniform height of all children.

Raises:

minute_interval #

minute_interval: int = 1

The granularity of the minute spinner.

Note

Must be a positive integer factor of 60.

Raises:

mode #

The mode of this picker.

second_interval #

second_interval: int = 1

The granularity of the second spinner.

Note

Must be a positive integer factor of 60.

Raises:

value #

value: DurationValue = field(
    default_factory=lambda: Duration()
)

The initial duration of the countdown timer.

If specified as an integer, it will be assumed to be in seconds.

Raises:

Events#

on_change #

on_change: (
    ControlEventHandler[CupertinoTimerPicker] | None
) = None

Called when the timer's duration changes.

The data property of the event handler contains the new duration value. Its type matches value: if value is a Duration, then data is also a Duration; otherwise, it is an int (seconds).