### Installing Flet with Extras Source: https://github.com/flet-dev/flet/blob/main/website/blog/2024-11-27-flet-v-0-25-release-announcement.md Examples of installing the Flet package with different extras for specific development or deployment needs. Recommended for development. ```bash flet[all] flet[cli] flet[web] flet[desktop] ``` -------------------------------- ### Quick Start Router Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/cookbook/router.md A basic Flet application demonstrating the Router with index and about routes. ```python import flet as ft @ft.component def Home(): return ft.Text("Welcome home!") @ft.component def About(): return ft.Text("About us") @ft.component def App(): return ft.Router([ ft.Route(index=True, component=Home), ft.Route(path="about", component=About), ]) ft.run(lambda page: page.render(App)) ``` -------------------------------- ### Install and Build Flet Website Locally Source: https://github.com/flet-dev/flet/blob/main/tools/crocodocs/README.md Commands to set up the Node.js environment, install dependencies, and build or start the Flet website locally. Requires Node.js 20+. ```bash # Requires Node.js 20+ nvm use 20 cd website yarn install yarn build # runs crocodocs generate + docusaurus build yarn start # runs crocodocs watch + docusaurus dev server ``` -------------------------------- ### Basic Routing Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/router.md Demonstrates the fundamental setup for routing within a Flet application. ```python import flet as ft def main(page: ft.Page): page.title = "Router Example" page.vertical_alignment = ft.MainAxisAlignment.CENTER def route_change(e): page.views.clear() page.views.append( ft.View( "/", [ ft.AppBar(title=ft.Text("Flet Router"), actions_alignment=ft.MainAxisAlignment.END), ft.Text("Welcome to the home page!"), ft.ElevatedButton("Go to About", on_click=lambda _: page.go("/about")), ], ) ) if page.route == "/about": page.views.append( ft.View( "/about", [ ft.AppBar(title=ft.Text("About Flet Router"), actions_alignment=ft.MainAxisAlignment.END), ft.Text("This is the about page."), ft.ElevatedButton("Go Home", on_click=lambda _: page.go("/")), ], ) ) page.update() page.on_route_change = route_change page.go("/") ft.app(target=main) ``` -------------------------------- ### Run Flet Python Example Source: https://github.com/flet-dev/flet/blob/main/CONTRIBUTING.md Creates and runs a minimal Flet application to verify the installation. The Flet client is downloaded on the first run. ```python import flet as ft def main(page: ft.Page): page.add(ft.Text("Hello, world!")) ft.run(main) ``` ```bash uv run python hello.py ``` -------------------------------- ### Showcase BlurStyle Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/types/blurstyle.md Demonstrates various BlurStyle options in Flet. Ensure the Flet library is installed and imported. ```python import flet as ft def main(page: ft.Page): page.title = "BlurStyle Showcase" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.horizontal_alignment = ft.CrossAxisAlignment.CENTER page.add( ft.Container( width=200, height=200, bgcolor=ft.colors.BLUE_ACCENT_700, border_radius=ft.border_radius.all(10), blur=ft.Blur(offset_x=5, offset_y=5, sigma=10), content=ft.Text("Blur offset and sigma"), ), ft.Container( width=200, height=200, bgcolor=ft.colors.GREEN_ACCENT_700, border_radius=ft.border_radius.all(10), blur=ft.BlurStyle.MATERIAL ), ft.Container( width=200, height=200, bgcolor=ft.colors.RED_ACCENT_700, border_radius=ft.border_radius.all(10), blur=ft.BlurStyle.TRANSPARENT ), ft.Container( width=200, height=200, bgcolor=ft.colors.YELLOW_ACCENT_700, border_radius=ft.border_radius.all(10), blur=ft.BlurStyle.NONE ), ) ft.app(target=main) ``` -------------------------------- ### Showcase Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/types/textcapitalization.md Demonstrates various TextCapitalization options in a Flet application. This example requires no special setup beyond a standard Flet app structure. ```python import flet as ft def main(page: ft.Page): page.title = "TextCapitalization Showcase" page.vertical_alignment = ft.MainAxisAlignment.CENTER def capitalize_change(e): txt_number.capitalization = ft.TextCapitalization(e.control.value) page.update() txt_number = ft.TextField( label="Enter text", capitalization=ft.TextCapitalization.WORDS, on_change=capitalize_change ) page.add( ft.Column([ txt_number, ft.RadioGroup( value=txt_number.capitalization.value, content=ft.Column([ ft.Radio(value=ft.TextCapitalization.NONE.value, content=ft.Text('None')), ft.Radio(value=ft.TextCapitalization.WORDS.value, content=ft.Text('Words')), ft.Radio(value=ft.TextCapitalization.SENTENCES.value, content=ft.Text('Sentences')), ft.Radio(value=ft.TextCapitalization.ALL.value, content=ft.Text('All')) ]), on_change=capitalize_change ) ]) ) ft.app(target=main) ``` -------------------------------- ### Basic SearchBar Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/searchbar.md Demonstrates the basic implementation of a SearchBar control. This snippet requires the Flet library to be installed. ```python import flet as ft def main(page: ft.Page): page.title = "Flet SearchBar Example" page.vertical_alignment = ft.MainAxisAlignment.CENTER def search_handler(e): page.add(ft.Text(f"You searched for: {e.control.value}")) page.add( ft.SearchBar( on_change=search_handler, label="Search here", icon=ft.icons.SEARCH, hint_text="Please enter your search query", alignment=ft.alignment.center, ) ) ft.app(target=main) ``` -------------------------------- ### Start TigerVNC Server Source: https://github.com/flet-dev/flet/wiki/Ubuntu-Server-Desktop-with-XFCE-and-VNC Starts the TigerVNC server on the Ubuntu machine, listening on localhost. This command initiates the VNC service. ```bash vncserver -localhost ``` -------------------------------- ### ScreenBrightness Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/services/screenbrightness.md Demonstrates how to use the ScreenBrightness class to set and get the screen brightness. Ensure the necessary imports are included. ```python import flet as ft def main(page: ft.Page): page.title = "Screen Brightness Example" page.vertical_alignment = ft.MainAxisAlignment.CENTER def set_brightness_click(e): try: brightness = float(brightness_input.value) if 0.0 <= brightness <= 1.0: ft.ScreenBrightness.set_brightness(brightness) status_text.value = f"Brightness set to {brightness:.2f}" else: status_text.value = "Brightness must be between 0.0 and 1.0" except ValueError: status_text.value = "Invalid input. Please enter a number." page.update() def get_brightness_click(e): current_brightness = ft.ScreenBrightness.get_brightness() status_text.value = f"Current brightness: {current_brightness:.2f}" page.update() brightness_input = ft.TextField(label="Set brightness (0.0-1.0)", width=200) set_button = ft.ElevatedButton("Set Brightness", on_click=set_brightness_click) get_button = ft.ElevatedButton("Get Brightness", on_click=get_brightness_click) status_text = ft.Text("Status: Idle") page.add( ft.Column( [ brightness_input, set_button, get_button, status_text ], horizontal_alignment=ft.CrossAxisAlignment.CENTER ) ) ft.app(target=main) ``` -------------------------------- ### Basic Lottie Animation Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/lottie/index.md Demonstrates how to use the Lottie control to display an animation. Ensure the flet-lottie package is installed. ```python import flet as ft from flet_lottie import Lottie def main(page: ft.Page): page.title = "Flet Lottie Example" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( Lottie( url=f"https://flet.dev/img/flet-logo.json", width=200, height=200, ) ) ft.app(target=main) ``` -------------------------------- ### Basic ExpansionPanelList Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/expansionpanellist.md Demonstrates the basic usage of the ExpansionPanelList control. This snippet requires no special setup beyond importing the necessary Flet components. ```python import flet as ft def main(page: ft.Page): page.title = "ExpansionPanelList Basic Demo" page.vertical_alignment = ft.MainAxisAlignment.START page.add( ft.ExpansionPanelList( controls=[ ft.ExpansionPanel( list_item=ft.ListTile( leading=ft.Icon(ft.icons.INFO), title=ft.Text("Panel 1") ), content=ft.Container( ft.Text("Content for Panel 1"), padding=10 ) ), ft.ExpansionPanel( list_item=ft.ListTile( leading=ft.Icon(ft.icons.FAVORITE), title=ft.Text("Panel 2") ), content=ft.Container( ft.Text("Content for Panel 2"), padding=10 ) ) ] ) ) ft.app(target=main) ``` -------------------------------- ### Set Up Python SDK with uv Source: https://github.com/flet-dev/flet/blob/main/CONTRIBUTING.md Navigate to the Python SDK directory and synchronize packages using uv. ```bash cd sdk/python uv sync ``` -------------------------------- ### Showcase Example of NavigationBarLabelBehavior Source: https://github.com/flet-dev/flet/blob/main/website/docs/types/navigationbarlabelbehavior.md Demonstrates the usage of NavigationBarLabelBehavior in a Flet application. This example requires the 'flet' library to be installed. ```python import flet as ft def main(page: ft.Page): page.title = "NavigationBarLabelBehavior" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( ft.NavigationBar( destinations=[ ft.NavigationDestination(icon=ft.icons.HOME, label="Home"), ft.NavigationDestination(icon=ft.icons.SEARCH, label="Search"), ft.NavigationDestination(icon=ft.icons.SETTINGS, label="Settings"), ] ), ft.NavigationBar( label_behavior=ft.NavigationBarLabelBehavior.SHOW_UNLABELED, destinations=[ ft.NavigationDestination(icon=ft.icons.HOME, label="Home"), ft.NavigationDestination(icon=ft.icons.SEARCH, label="Search"), ft.NavigationDestination(icon=ft.icons.SETTINGS, label="Settings"), ] ), ft.NavigationBar( label_behavior=ft.NavigationBarLabelBehavior.HIDE_LABELS, destinations=[ ft.NavigationDestination(icon=ft.icons.HOME, label="Home"), ft.NavigationDestination(icon=ft.icons.SEARCH, label="Search"), ft.NavigationDestination(icon=ft.icons.SETTINGS, label="Settings"), ] ), ft.NavigationBar( label_behavior=ft.NavigationBarLabelBehavior.SHOW_ALWAYS, destinations=[ ft.NavigationDestination(icon=ft.icons.HOME, label="Home"), ft.NavigationDestination(icon=ft.icons.SEARCH, label="Search"), ft.NavigationDestination(icon=ft.icons.SETTINGS, label="Settings"), ] ), ) ft.app(target=main) ``` -------------------------------- ### Showcase Example of CardVariant Source: https://github.com/flet-dev/flet/blob/main/website/docs/types/cardvariant.md Demonstrates the usage of CardVariant in a Flet application. This example requires the Flet library to be installed. ```python import flet as ft def main(page: ft.Page): page.title = "CardVariant Showcase" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( ft.Column( [ ft.Text("Default Card:"), ft.Card( content=ft.Container( content=ft.Text("This is a default card."), width=200, height=100, alignment=ft.alignment.center, ), ), ft.Text("Elevated Card:"), ft.Card( variant=ft.CardVariant.ELEVATED, content=ft.Container( content=ft.Text("This is an elevated card."), width=200, height=100, alignment=ft.alignment.center, ), ), ft.Text("Outline Card:"), ft.Card( variant=ft.CardVariant.OUTLINE, content=ft.Container( content=ft.Text("This is an outline card."), width=200, height=100, alignment=ft.alignment.center, ), ), ] ) ) ft.app(target=main) ``` -------------------------------- ### Showcase Example of BorderSideStrokeAlign Source: https://github.com/flet-dev/flet/blob/main/website/docs/types/bordersidestrokealign.md Demonstrates the usage of BorderSideStrokeAlign in a Flet application. This example requires the Flet library to be installed. ```python import flet as ft def main(page: ft.Page): page.title = "BorderSideStrokeAlign" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( ft.Container( content=ft.Text("Hello World!"), alignment=ft.alignment.center, width=200, height=100, bgcolor=ft.colors.BLUE_GREY_100, border_radius=ft.border_radius.all(10), border=ft.border.all( width=5, color=ft.colors.BLUE_GREY_400, side=ft.BorderSide(stroke_align=ft.BorderSideStrokeAlign.CENTER), ), ) ) ft.app(target=main) ``` -------------------------------- ### Set Up Flutter Client Source: https://github.com/flet-dev/flet/blob/main/CONTRIBUTING.md Navigate to the client directory and fetch Flutter dependencies using fvm. ```bash cd client fvm flutter pub get ``` -------------------------------- ### Basic NavigationBar Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/navigationbar/index.md Demonstrates a simple implementation of the NavigationBar control. This example shows how to set up the navigation bar with items. ```python import flet as ft def main(page: ft.Page): page.title = "NavigationBar Example" page.vertical_alignment = ft.MainAxisAlignment.END page.navigation_bar = ft.NavigationBar( destinations=[ ft.NavigationDestination(icon=ft.icons.HOME, label="Home"), ft.NavigationDestination(icon=ft.icons.SEARCH, label="Search"), ft.NavigationDestination(icon=ft.icons.SETTINGS, label="Settings"), ] ) page.update() ft.app(target=main) ``` -------------------------------- ### Showcase ThemeMode Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/types/thememode.md Demonstrates the usage of ThemeMode in a Flet application. This example requires a Python environment with Flet installed. ```python import flet as ft def main(page: ft.Page): page.title = "ThemeMode" page.theme_mode = ft.ThemeMode.LIGHT def change_theme_mode(e): page.theme_mode = ft.ThemeMode.DARK if page.theme_mode == ft.ThemeMode.LIGHT else ft.ThemeMode.LIGHT page.update() page.add( ft.Text("This is a text."), ft.ElevatedButton("Change theme mode", on_click=change_theme_mode) ) ft.app(target=main) ``` -------------------------------- ### Showcase Example of StrokeCap Source: https://github.com/flet-dev/flet/blob/main/website/docs/types/strokecap.md Demonstrates the usage of StrokeCap in a Flet application. This example requires a Python environment with Flet installed. ```python import flet as ft def main(page: ft.Page): page.title = "StrokeCap Showcase" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( ft.Column( [ ft.Text("StrokeCap.ROUND:", weight=ft.FontWeight.BOLD), ft.Container( content=ft.Text("This is a rounded stroke cap."), bgcolor=ft.colors.BLUE_GREY_100, padding=10, border_radius=ft.border_radius.all(0), ink=True, on_click=lambda e: print("Clicked!"), width=200, height=50, alignment=ft.alignment.center, stroke_cap=ft.StrokeCap.ROUND # Example of setting StrokeCap ), ft.Text("StrokeCap.SQUARE:", weight=ft.FontWeight.BOLD), ft.Container( content=ft.Text("This is a square stroke cap."), bgcolor=ft.colors.BLUE_GREY_100, padding=10, border_radius=ft.border_radius.all(0), ink=True, on_click=lambda e: print("Clicked!"), width=200, height=50, alignment=ft.alignment.center, stroke_cap=ft.StrokeCap.SQUARE # Example of setting StrokeCap ), ft.Text("StrokeCap.BUTT:", weight=ft.FontWeight.BOLD), ft.Container( content=ft.Text("This is a butt stroke cap."), bgcolor=ft.colors.BLUE_GREY_100, padding=10, border_radius=ft.border_radius.all(0), ink=True, on_click=lambda e: print("Clicked!"), width=200, height=50, alignment=ft.alignment.center, stroke_cap=ft.StrokeCap.BUTT # Example of setting StrokeCap ), ], horizontal_alignment=ft.CrossAxisAlignment.CENTER, spacing=20 ) ) ft.app(target=main) ``` -------------------------------- ### Initialize virtual environment Source: https://github.com/flet-dev/flet/blob/main/website/docs/publish/web/dynamic-website/hosting/self-hosting.md Commands to create a virtual environment and install dependencies. ```bash python -m venv .venv source .venv/bin/activate pip install -r requirements.txt ``` -------------------------------- ### Showcase Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/types/scrolltype.md Demonstrates various ScrollType options in a Flet application. This example requires a Flet application setup to run. ```python import flet as ft def main(page: ft.Page): page.title = "ScrollType Showcase" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( ft.Column( [ ft.Text("ScrollType.ADAPTIVE:"), ft.ListView( height=150, scroll=ft.ScrollType.ADAPTIVE, controls=[ ft.Container(height=50, bgcolor=ft.colors.RED_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.GREEN_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.BLUE_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.RED_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.GREEN_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.BLUE_ACCENT_100), ], ), ft.Text("ScrollType.ALWAYS:"), ft.ListView( height=150, scroll=ft.ScrollType.ALWAYS, controls=[ ft.Container(height=50, bgcolor=ft.colors.RED_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.GREEN_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.BLUE_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.RED_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.GREEN_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.BLUE_ACCENT_100), ], ), ft.Text("ScrollType.DRAGGING:"), ft.ListView( height=150, scroll=ft.ScrollType.DRAGGING, controls=[ ft.Container(height=50, bgcolor=ft.colors.RED_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.GREEN_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.BLUE_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.RED_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.GREEN_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.BLUE_ACCENT_100), ], ), ft.Text("ScrollType.NONE:"), ft.ListView( height=150, scroll=ft.ScrollType.NONE, controls=[ ft.Container(height=50, bgcolor=ft.colors.RED_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.GREEN_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.BLUE_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.RED_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.GREEN_ACCENT_100), ft.Container(height=50, bgcolor=ft.colors.BLUE_ACCENT_100), ], ), ], spacing=10, ) ) ft.app(target=main) ``` -------------------------------- ### Start local development server Source: https://github.com/flet-dev/flet/blob/main/website/README.md Starts a local development server with live reloading enabled. ```bash $ yarn start ``` -------------------------------- ### CupertinoRadio Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/cupertinoradio.md Demonstrates how to use the CupertinoRadio control in a Flet application. This example shows a basic setup for a radio button. ```python import flet as ft def main(page: ft.Page): page.title = "CupertinoRadio Example" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( ft.Column([ ft.Text("Pick one:"), ft.CupertinoRadio(value="red", label="Red"), ft.CupertinoRadio(value="green", label="Green"), ft.CupertinoRadio(value="blue", label="Blue"), ]) ) ft.app(target=main) ``` -------------------------------- ### Music Info Card Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/card.md Demonstrates how to create a Card control to display music information. This example showcases basic Card usage with content. ```python import flet as ft def main(page: ft.Page): page.title = "Music Info" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( ft.Card( content=ft.Container( content=ft.Column([ ft.ListTile( leading=ft.Icon(ft.icons.ALBUM), title=ft.Text("The Enchanted Nightingale"), subtitle=ft.Text("Explore the beauty of this classic story."), ) ]), width=300, padding=10, ) ) ) ft.app(target=main) ``` -------------------------------- ### Showcase ScrollMode Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/types/scrollmode.md Demonstrates various ScrollMode options in a Flet application. This example requires a Python environment with Flet installed. ```python import flet as ft def main(page: ft.Page): page.title = "ScrollMode Showcase" page.vertical_alignment = ft.MainAxisAlignment.CENTER def create_scrollable_container(mode: ft.ScrollMode, title: str): return ft.Container( content=ft.Column([ ft.Text(title), ft.Container( height=150, width=200, bgcolor=ft.colors.BLUE_GREY_100, content=ft.Column([ ft.Container(height=300, bgcolor=ft.colors.BLUE_GREY_200), ft.Container(height=300, bgcolor=ft.colors.BLUE_GREY_300), ]), scroll=mode, border=ft.border.all(1, ft.colors.BLUE_GREY_400), ) ]), padding=10, ) page.add( ft.Row( [ create_scrollable_container(ft.ScrollMode.AUTO, "AUTO"), create_scrollable_container(ft.ScrollMode.SCROLL, "SCROLL"), create_scrollable_container(ft.ScrollMode.NONE, "NONE"), create_scrollable_container(ft.ScrollMode.ADAPTIVE, "ADAPTIVE"), ], wrap=True, alignment=ft.MainAxisAlignment.CENTER, ) ) ft.app(target=main) ``` -------------------------------- ### Showcase Example of LaunchMode Source: https://github.com/flet-dev/flet/blob/main/website/docs/types/launchmode.md Demonstrates various launch modes in a Flet application. This example requires a Python environment with Flet installed. ```python import flet as ft def main(page: ft.Page): page.title = "Launch Mode Showcase" page.vertical_alignment = ft.MainAxisAlignment.CENTER def show_message(e): ft.app(target=main, launch_mode=ft.LaunchMode.DUPLICATE_IF_NEEDED) page.add( ft.Column([ ft.Text("Click the button to launch another instance."), ft.ElevatedButton("Launch App", on_click=show_message), ]) ) ft.app(target=main, view=ft.AppView.WEB_BROWSER) ft.app(target=main, launch_mode=ft.LaunchMode.DUPLICATE_IF_NEEDED) ft.app(target=main, launch_mode=ft.LaunchMode.SINGLE_INSTANCE) ft.app(target=main, launch_mode=ft.LaunchMode.ALWAYS_REPEAT) ``` -------------------------------- ### Install dependencies Source: https://github.com/flet-dev/flet/blob/main/website/README.md Run this command to install all required project dependencies. ```bash $ yarn ``` -------------------------------- ### Example: Create a Specific iOS Simulator Source: https://github.com/flet-dev/flet/blob/main/website/blog/2025-12-02-flet-debug-the-new-cli-for-testing-flet-apps-on-mobile-devices.md An example of creating an iOS simulator named 'My iPhone 17 Pro' using the 'iPhone 17 Pro' device type and the corresponding iOS runtime. ```bash xcrun simctl create "My iPhone 17 Pro" "iPhone 17 Pro" com.apple.CoreSimulator.SimRuntime.iOS-26-1 ``` -------------------------------- ### Showcase Example of DatePickerEntryMode Source: https://github.com/flet-dev/flet/blob/main/website/docs/types/datepickerentrymode.md Demonstrates various ways DatePickerEntryMode can be used in a Flet application. This example requires the flet library to be installed. ```python import flet as ft def main(page: ft.Page): page.title = "DatePickerEntryMode Showcase" page.vertical_alignment = ft.MainAxisAlignment.CENTER def show_date_picker(e): dp = ft.DatePicker( current_date=dt.value, on_change=lambda d: dt.update() if isinstance(d.control.value, datetime.date) else None, first_date=datetime.date(2021, 1, 1), last_date=datetime.date(2024, 12, 31), entry_mode=ft.DatePickerEntryMode.CALENDAR_ONLY ) page.dialog = ft.AlertDialog( content=dp, actions=[ft.TextButton("OK", on_click=lambda _: page.close("dialog"))], modal=True ) dp.open() dt = ft.TextField(label="Date", on_tap=show_date_picker, read_only=True) page.add(dt) ft.app(target=main) ``` -------------------------------- ### Enable Startup Screen in pyproject.toml Source: https://github.com/flet-dev/flet/blob/main/website/docs/publish/index.md Configure the startup screen to be shown while the app and runtime are initializing by setting 'show' to true and providing a custom message in pyproject.toml. ```toml [tool.flet.app.startup_screen] # or [tool.flet..app.startup_screen] show = true message = "Starting up the app…" ``` -------------------------------- ### BlockPicker Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/colorpickers/blockpicker.md Demonstrates how to use the BlockPicker control in a Flet application. This example shows a basic setup with the picker displayed on the page. ```python import flet as ft def main(page: ft.Page): page.title = "BlockPicker Example" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( ft.BlockPicker( options=[ ft.BlockPickerOption("red", ft.colors.RED_ACCENT_700), ft.BlockPickerOption("green", ft.colors.GREEN_ACCENT_700), ft.BlockPickerOption("blue", ft.colors.BLUE_ACCENT_700), ft.BlockPickerOption("yellow", ft.colors.YELLOW_ACCENT_700), ft.BlockPickerOption("orange", ft.colors.ORANGE_ACCENT_700), ft.BlockPickerOption("purple", ft.colors.PURPLE_ACCENT_700), ft.BlockPickerOption("cyan", ft.colors.CYAN_ACCENT_700), ft.BlockPickerOption("pink", ft.colors.PINK_ACCENT_700), ] ) ) ft.app(target=main) ``` -------------------------------- ### Install Provisioning Profile Source: https://github.com/flet-dev/flet/blob/main/website/docs/publish/ios.md Copies a provisioning profile to the required system directory with the correct UUID-based filename. ```bash cp ~/Downloads/{profile-name}.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/${profile_uuid}.mobileprovision ``` -------------------------------- ### CandlestickChart Python Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/charts/candlestickchart.md A basic example demonstrating how to create and display a CandlestickChart in a Flet application. This snippet requires the Flet library to be installed. ```python import flet as ft def main(page: ft.Page): page.title = "Flet CandlestickChart" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( ft.CandlestickChart( data_points=[ ft.CandlestickChartDataPoint( time=ft.datetime(2023, 1, 1, 9, 0), open=100, high=110, low=95, close=105, ), ft.CandlestickChartDataPoint( time=ft.datetime(2023, 1, 1, 10, 0), open=105, high=115, low=100, close=112, ), ft.CandlestickChartDataPoint( time=ft.datetime(2023, 1, 1, 11, 0), open=112, high=118, low=108, close=110, ), ], width=400, height=300, ) ) ft.app(target=main) ``` -------------------------------- ### Install Full Flet Desktop Client Source: https://github.com/flet-dev/flet/blob/main/website/blog/2024-10-10-flet-new-packaging-pre-release.md Install the full Flet desktop client, including Audio and Video controls, by specifying the version and package name. ```bash pip install flet-desktop==0.25.0.dev3519 ``` -------------------------------- ### BoxFit Showcase Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/types/boxfit.md Demonstrates various BoxFit values in a Python Flet application. This example requires a Flet app setup to run. ```python import flet as ft def main(page: ft.Page): page.title = "BoxFit Showcase" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.horizontal_alignment = ft.CrossAxisAlignment.CENTER def create_image_container(box_fit_value): return ft.Container( content=ft.Image( src="https://picsum.photos/200/200", width=100, height=100, fit=box_fit_value, ), width=150, height=150, bgcolor=ft.colors.BLUE_GREY_100, alignment=ft.alignment.center, ) page.add( ft.Column( [ ft.Text("BoxFit.CONTAIN:"), create_image_container(ft.BoxFit.CONTAIN), ft.Text("BoxFit.COVER:"), create_image_container(ft.BoxFit.COVER), ft.Text("BoxFit.FILL:"), create_image_container(ft.BoxFit.FILL), ft.Text("BoxFit.FIT_HEIGHT:"), create_image_container(ft.BoxFit.FIT_HEIGHT), ft.Text("BoxFit.FIT_WIDTH:"), create_image_container(ft.BoxFit.FIT_WIDTH), ft.Text("BoxFit.NONE:"), create_image_container(ft.BoxFit.NONE), ft.Text("BoxFit.SCALE_DOWN:"), create_image_container(ft.BoxFit.SCALE_DOWN), ], spacing=10, horizontal_alignment=ft.CrossAxisAlignment.CENTER, ) ) ft.app(target=main) ``` -------------------------------- ### Initialize Project Directory Source: https://github.com/flet-dev/flet/blob/main/website/docs/getting-started/installation.md Create and enter a new directory for a Flet project. ```bash mkdir my-app cd my-app ``` -------------------------------- ### Python SelectionArea Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/selectionarea.md Demonstrates how to use the SelectionArea control in Python. This example shows a basic setup where text within the SelectionArea can be selected. ```python import flet as ft def main(page: ft.Page): page.title = "SelectionArea Example" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( ft.SelectionArea( content=ft.Text("This text can be selected.") ) ) ft.app(target=main) ``` -------------------------------- ### Basic Declarative Router Example Source: https://github.com/flet-dev/flet/blob/main/website/blog/2026-05-11-flet-v-0-85-release-announcement.md Demonstrates the simplest implementation of ft.Router for declarative navigation between Home and About pages. ```python import flet as ft @ft.component def Home(): return ft.Text("Home page", size=24) @ft.component def About(): return ft.Text("About page", size=24) @ft.component def App(): return ft.SafeArea( content=ft.Column([ ft.Row([ ft.Button("Home", on_click=lambda: ft.context.page.navigate("/")), ft.Button("About", on_click=lambda: ft.context.page.navigate("/about")), ]), ft.Router([ ft.Route(index=True, component=Home), ft.Route(path="about", component=About), ]), ]) ) ft.run(lambda page: page.render(App)) ``` -------------------------------- ### FilePicker Example: Pick and Upload Files Source: https://github.com/flet-dev/flet/blob/main/website/docs/services/filepicker.md Demonstrates how to pick multiple files and then upload them using the FilePicker service. ```python import flet as ft def main(page: ft.Page): page.title = "File Picker Upload Demo" page.vertical_alignment = ft.MainAxisAlignment.CENTER def upload_files_result(e: ft.FilePickerUploadFileResult): if e.files: for f in e.files: print(f"Uploading {f.name} to {f.url}") # You can also access file content via f.content # print(f"Content of {f.name}: {f.content}") else: print("No files uploaded.") page.update() file_picker = ft.FilePicker(on_upload_result=upload_files_result) page.overlay.append(file_picker) def pick_and_upload_files(e): file_picker.pick_files( "Pick files to upload...", allow_multiple=True, upload=True # Set upload=True to upload files immediately after picking ) page.add( ft.Column([ ft.ElevatedButton( "Pick and upload files", icon=ft.icons.UPLOAD, on_click=pick_and_upload_files, ) ]) ) ft.app(target=main) ``` -------------------------------- ### Audio Playback Controls Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/services/audio/index.md Example demonstrating audio playback controls using the Flet Audio control. This snippet requires the flet-audio package to be installed. ```python import flet as ft from flet_audio import Audio def main(page: ft.Page): page.title = "Audio Playback" page.vertical_alignment = ft.MainAxisAlignment.CENTER audio_player = Audio( src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3", autoplay=False, volume=1.0, on_loaded=lambda e: print("Audio loaded"), on_ended=lambda e: print("Audio ended"), on_error=lambda e: print("Audio error: ", e.data) ) page.add( ft.Column([ audio_player, ft.ElevatedButton("Play", on_click=lambda e: audio_player.play()), ft.ElevatedButton("Pause", on_click=lambda e: audio_player.pause()), ft.ElevatedButton("Resume", on_click=lambda e: audio_player.resume()), ft.ElevatedButton("Stop", on_click=lambda e: audio_player.stop()), ]) ) ft.app(target=main) ``` -------------------------------- ### Main Program Setup Source: https://github.com/flet-dev/flet/blob/main/website/docs/tutorials/solitaire.md Sets up the main Flet application to run the Solitaire game. It imports the Solitaire class and adds an instance of it to the page. ```python import flet as ft from solitaire import Solitaire def main(page: ft.Page): solitaire = Solitaire() page.add(solitaire) ft.run(main) ``` -------------------------------- ### Share Content Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/services/share.md Demonstrates how to use the Share service to share text and a URL. Ensure the Share service is imported. ```python import flet as ft def main(page: ft.Page): page.title = "Flet Share Example" def share_content(e): page.share( text="Check out this cool app!", url="https://flet.dev/", title="Share Content" ) page.add( ft.ElevatedButton("Share Content", on_click=share_content) ) ft.app(target=main) ``` -------------------------------- ### FilePicker Example: Pick, Save, and Get Directory Path Source: https://github.com/flet-dev/flet/blob/main/website/docs/services/filepicker.md Demonstrates the core functionalities of FilePicker including picking files, saving files, and getting a directory path. ```python import flet as ft def main(page: ft.Page): page.title = "File Picker Demo" page.vertical_alignment = ft.MainAxisAlignment.CENTER def pick_file_result(e): file_paths = [] if e.files: for f in e.files: file_paths.append(f.path) txt_paths.hstack(file_paths) else: txt_paths.value = "File(s) not picked." page.update() def save_file_result(e): if e.file_type: txt_save_path.value = f"File saved to: {e.path}" else: txt_save_path.value = "File not saved." page.update() def get_directory_result(e): if e.path: txt_dir_path.value = f"Directory selected: {e.path}" else: txt_dir_path.value = "Directory not selected." page.update() file_picker = ft.FilePicker(on_result=pick_file_result) save_file_picker = ft.FilePicker(on_result=save_file_result) get_directory_picker = ft.FilePicker(on_result=get_directory_result) page.overlay.extend([ file_picker, save_file_picker, get_directory_picker, ]) txt_paths = ft.Text("No files picked.") txt_save_path = ft.Text("No file saved.") txt_dir_path = ft.Text("No directory selected.") page.add( ft.Column([ ft.Row([ ft.ElevatedButton( "Pick files", icon=ft.icons.UPLOAD_FILE, on_click=lambda _: file_picker.pick_files( "Select one or more files...", allow_multiple=True ), ), txt_paths, ]), ft.Row([ ft.ElevatedButton( "Save file", icon=ft.icons.SAVE, on_click=lambda _: save_file_picker.save_file( "Save file as...", "my_file.txt", file_type=ft.FilePickerFileType.TEXT, ), ), txt_save_path, ]), ft.Row([ ft.ElevatedButton( "Get directory path", icon=ft.icons.FOLDER_OPEN, on_click=lambda _: get_directory_picker.get_directory_path( "Select a directory..." ), ), txt_dir_path, ]), ]) ) ft.app(target=main) ``` -------------------------------- ### Video Playback Controls Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/video/index.md Shows how to implement custom playback controls for the Video control. ```python import flet as ft from flet_video import Video def main(page: ft.Page): page.title = "Video Playback Controls" page.vertical_alignment = ft.MainAxisAlignment.CENTER video = Video( playlist=[ "https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4", "https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4", ], autoplay=True, expand=True, ) def play_pause(e): video.play_pause() def next_video(e): video.next() def prev_video(e): video.prev() page.add( video, ft.Row( [ft.IconButton(ft.icons.PLAY_ARROW, on_click=play_pause), ft.IconButton(ft.icons.SKIP_NEXT, on_click=next_video), ft.IconButton(ft.icons.SKIP_PREVIOUS, on_click=prev_video)], alignment=ft.MainAxisAlignment.CENTER, ), ) ft.app(target=main) ``` -------------------------------- ### SnackBar with Counter Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/snackbar.md Shows how to implement a SnackBar that includes a counter, often used for temporary notifications or status updates. This example requires a basic Flet app setup. ```python import flet as ft def main(page: ft.Page): page.title = "SnackBar Counter Demo" page.vertical_alignment = ft.MainAxisAlignment.CENTER def show_snack_bar(e): page.snack_bar = ft.SnackBar( ft.Text("This is a SnackBar with a counter!"), open=True, duration=4000, ) page.snack_bar.open = True page.update() page.add( ft.ElevatedButton("Show SnackBar", on_click=show_snack_bar) ) ft.app(target=main) ``` -------------------------------- ### Basic Shimmer Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/shimmer.md Demonstrates the basic usage of the Shimmer control for a loading placeholder. ```python import flet as ft def main(page: ft.Page): page.title = "Shimmer Basic" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( ft.Column([ ft.Text("Shimmer effect:"), ft.Shimmer( content=ft.Container( width=200, height=100, bgcolor=ft.colors.BLUE_GREY_100, border_radius=5 ) ), ft.Text("Shimmer with basic placeholder:"), ft.Shimmer( content=ft.Container( width=200, height=100, bgcolor=ft.colors.BLUE_GREY_100, border_radius=5 ), is_container=True, ), ]) ) ft.app(target=main) ``` -------------------------------- ### Get All Keys with a Prefix Source: https://github.com/flet-dev/flet/blob/main/website/docs/cookbook/client-storage.md Retrieve all keys that start with a specified prefix using `page.shared_preferences.get_keys()`. ```python await page.shared_preferences.get_keys("key-prefix.") ``` -------------------------------- ### CupertinoSwitch Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/cupertinoswitch.md Demonstrates how to use the CupertinoSwitch control. This example shows a basic implementation of the switch. ```python import flet as ft def main(page: ft.Page): page.title = "CupertinoSwitch Example" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( ft.Column( [ ft.Text("Cupertino Switch:"), ft.CupertinoSwitch(value=True, tristate=True), ft.CupertinoSwitch(value=False, tristate=False), ], horizontal_alignment=ft.CrossAxisAlignment.CENTER, ) ) ft.app(target=main) ``` -------------------------------- ### Basic ExpansionTile Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/expansiontile.md Demonstrates the fundamental usage of the ExpansionTile control to create a collapsible section. ```python import flet as ft def main(page: ft.Page): page.title = "ExpansionTile Basic" page.vertical_alignment = ft.MainAxisAlignment.START page.add( ft.ExpansionTile( title=ft.Text("Expandable Title"), children=[ ft.ListTile(title=ft.Text("Item 1"), leading=ft.Icon(ft.icons.INFO)), ft.ListTile(title=ft.Text("Item 2"), leading=ft.Icon(ft.icons.FAVORITE)), ], ) ) ft.app(target=main) ``` -------------------------------- ### Wired CupertinoNavigationBar Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/cupertinonavigationbar.md Shows a more complex CupertinoNavigationBar setup, potentially for a wired or custom layout. ```python import flet as ft def main(page: ft.Page): page.title = "Wired Cupertino Navigation Bar Example" page.vertical_alignment = ft.MainAxisAlignment.START page.add( ft.CupertinoNavigationBar( [ft.Text("Title")], bgcolor=ft.colors.BLUE_GREY_900, leading=ft.Icon(ft.icons.MENU), trailing=ft.Row([ ft.Icon(ft.icons.SEARCH), ft.Icon(ft.icons.MORE_VERT) ]) ) ) ft.app(target=main) ``` -------------------------------- ### Route Loaders Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/router.md Demonstrates how to use loaders to asynchronously load content for a route. ```python import flet as ft import asyncio def main(page: ft.Page): page.title = "Route Loaders Example" async def load_data(route): await asyncio.sleep(1) # Simulate network delay return ft.Text(f"Data loaded for {route}") def route_change(e): page.views.clear() page.views.append( ft.View( "/", [ ft.AppBar(title=ft.Text("Route Loaders"), actions_alignment=ft.MainAxisAlignment.END), ft.Text("Loading..."), ft.ElevatedButton("Go to Data", on_click=lambda _: page.go("/data")), ], ) ) if page.route == "/data": page.views.append( ft.View( "/data", [ ft.AppBar(title=ft.Text("Data Page"), actions_alignment=ft.MainAxisAlignment.END), ft.Container(content=ft.ProgressRing()), ], on_view_ready=lambda _: page.run_async(update_data_view), ) ) page.update() async def update_data_view(): await asyncio.sleep(1) # Simulate loading data_content = await load_data("/data") page.views[-1].controls.append(data_content) page.update() page.on_route_change = route_change page.go("/") ft.app(target=main) ``` -------------------------------- ### Basic Flashlight Control Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/services/flashlight/index.md A Python example demonstrating how to control the device flashlight within a Flet application using the flet-flashlight extension. ```python import flet as ft from flet_flashlight import Flashlight def main(page: ft.Page): page.title = "Flashlight App" page.vertical_alignment = ft.MainAxisAlignment.CENTER def toggle_flashlight(e): if flashlight.is_on: flashlight.turn_off() e.control.icon = ft.icons.LIGHT e.control.tooltip = "Turn on flashlight" else: flashlight.turn_on() e.control.icon = ft.icons.HIGHLIGHT_OFF e.control.tooltip = "Turn off flashlight" page.update() flashlight = Flashlight() page.add( ft.IconButton( icon=ft.icons.LIGHT, tooltip="Turn on flashlight", on_click=toggle_flashlight, ) ) ft.app(target=main) ``` -------------------------------- ### Install XFCE Desktop Environment Source: https://github.com/flet-dev/flet/wiki/Ubuntu-Server-Desktop-with-XFCE-and-VNC Installs the XFCE desktop environment and related utilities on Ubuntu Server. This is a prerequisite for setting up a graphical interface. ```bash sudo apt update sudo apt install -y xfce4 xfce4-goodies ``` -------------------------------- ### WebView Example Source: https://github.com/flet-dev/flet/blob/main/website/docs/controls/webview/index.md A basic example demonstrating the usage of the WebView control in a Flet application. ```python import flet as ft def main(page: ft.Page): page.title = "WebView Example" page.vertical_alignment = ft.MainAxisAlignment.CENTER page.add( ft.WebView( url="https://www.google.com", width=400, height=300, ) ) ft.app(target=main) ```