Assets

Overview

Assets are files bundled and deployed with a Flet application, accessible at runtime. Common types include static data (JSON), configuration files, icons, images, and videos.

Configuration

  • **assets_dir parameter in ft.run()**: Specifies the directory containing local assets.
  • * Defaults to "assets". * Can be an absolute path or relative to the app's entry point.

    Usage

  • Assets are accessed using relative paths within Flet controls.
  • The src property of controls like ft.Image should point to the asset's path relative to the assets_dir.
  • Example: Displaying a Local Image

    **Directory Structure:**

    assets/
    └── images/
        └── sample.png
    main.py
    

    **Python Code:**

    import flet as ft

    def main(page: ft.Page): page.add( ft.Image(src="images/sample.png") )

    ft.run(main, assets_dir="assets")

    This approach is applicable to other asset types such as fonts, Lottie animations, and Rive files.