Publishing Flet App

Use the flet build command to package Flet applications into standalone executables or installable packages.

Prerequisites

  • **Platform Matrix**: Defines which OS to run flet build on for specific target platforms (Android, iOS, macOS, Linux, Windows, Web).
  • **Flutter SDK**: Required for all builds. If not in PATH, it's downloaded automatically.
  • Project Structure

    Assumes a standard structure:

    README.md
    pyproject.toml
    src/
      assets/
        icon.png
      main.py
    
    requirements.txt can be used instead of pyproject.toml, but flet build prioritizes pyproject.toml. Avoid pip freeze for requirements.txt.

    How it works

    1. Creates an ephemeral Flutter project from a template. 2. Copies custom assets (icons, splash images). 3. Generates platform-specific icons and splash screens. 4. Packages the Python app using serious_python. 5. Runs flutter build . 6. Copies build results to build/.

    Including Extensions

    Add third-party Flet extensions to your project's dependencies in pyproject.toml or requirements.txt.

    Configuration Options

  • **Product Name**: User-facing application name. Set via --product CLI or tool.flet.product in pyproject.toml.
  • **Company Name**: Company name for metadata. Set via --company CLI or tool.flet.company in pyproject.toml.
  • **Copyright**: Copyright text for metadata. Set via --copyright CLI or tool.flet.copyright in pyproject.toml.
  • **Flutter Dependencies**: Add Flutter packages via tool.flet.flutter.dependencies in pyproject.toml.
  • **Custom Output Directory**: Specify build output location with --output CLI or tool.flet.output in pyproject.toml.
  • Assets

  • **Icons**: Customize app icons (except Linux) using files in the assets directory (icon_ios.png, icon_android.png, icon_web.png, icon_windows.ico/.png, icon_macos.png). Fallback to icon.png.
  • **Splash Screen**: Customize splash screens for iOS, Android, and Web using images in assets (splash_dark_ios.png, splash_ios.png, etc.). Fallback order: platform-specific dark, platform-specific light, general dark, general, icon.
  • * **Splash Background Colors**: Set via --splash-color and --splash-dark-color CLI or tool.flet.splash.color/dark_color in pyproject.toml. * **Disabling Splash Screens**: Enabled by default; refer to platform-specific docs.

    Screen Settings

  • **Boot Screen**: Shown during app archive unpacking. Configurable via tool.flet.app.boot_screen (show, message) and platform-specific settings.
  • **Startup Screen**: Shown during Python app startup (Android only). Configurable via tool.flet.app.startup_screen (show, message) and platform-specific settings.
  • Advanced Options

  • **Hidden Window on Start**: For desktop apps, start with the window hidden. Enable via tool.flet.app.hide_window_on_start = true in pyproject.toml or -n with flet run.
  • **Entry Point**: Specify the main Python file if not main.py using --module-name CLI or tool.flet.app.module in pyproject.toml.
  • **Compilation and Cleanup**: Control Python file compilation (--compile-app, --compile-packages) and package cleanup (--cleanup-packages) via tool.flet.compile in pyproject.toml.
  • **Permissions**: Set cross-platform permissions (location, camera, microphone, photo_library) via --permissions CLI or tool.flet.permissions in pyproject.toml. Mappings to platform-specific Info.plist, entitlements, and AndroidManifest.xml are provided.
  • **Versioning**: Set build number (--build-number or tool.flet.build_number) and build version (--build-version or project.version/tool.poetry.version).
  • **Customizing Build Template**: Specify template source (--template or tool.flet.template.url), reference (--template-ref or tool.flet.template.ref), and directory (--template-dir or tool.flet.template.dir).
  • **Deep Linking**: Configure scheme and host for deep linking via --deep-linking-scheme/--deep-linking-host CLI or tool.flet.deep_linking in pyproject.toml.
  • **Project Name**: Set via --project CLI or tool.flet.project in pyproject.toml.
  • **Organization Name**: Set via --org CLI or tool.flet.org in pyproject.toml.
  • **Bundle ID**: Set via --bundle-id CLI or tool.flet.bundle_id in pyproject.toml (can be platform-specific).
  • **Additional flutter build Arguments**: Pass arguments to flutter build via --flutter-build-args CLI or tool.flet.flutter.build_args in pyproject.toml.
  • **Verbose Logging**: Enable detailed output with -v or -vv flags.
  • **Console Output**: Flet app output (print, logging) is redirected to console.log. Access via FLET_APP_CONSOLE env var. Special exit code 100 displays the log.