Skip to main content

Flet v0.24.0 Release Announcement

· 6 min read
Henri Ndonko
Flet Contributor and Maintainer

I am very happy to announce the release of Flet version 0.24.0! It comes with a very long list of bug fixes, several enhancements and new features.

New Controls

New Properties

  • AudioRecorder: cancel_recording()
  • Video: on_completed, on_track_changed
  • InputFilter: unicode, case_sensitive, dot_all, multiline
  • Geolocator: on_error, on_position_change
  • Barchart, LineChart: tooltip_border_side, tooltip_direction, tooltip_fit_inside_horizontally, tooltip_fit_inside_vertically, tooltip_horizontal_offset, tooltip_margin, tooltip_max_content_width, tooltip_padding, tooltip_rounded_radius, tooltip_rotate_angle
  • Container: decoration, foreground_decoration, ignore_interactions, image
  • Page, View: decoration, foreground_decoration
  • CupertinoTextField: enable_scribble, image, obscuring_character, padding, scroll_padding, on_click
  • DataTable: heading_row_alignment
  • TextField: counter, disabled_hint_content, options_fill_horizontally
  • ExpansionTile: min_tile_height, show_trailing_icon
  • Markdown: fit_content, img_error_content, md_style_sheet, shrink_wrap, soft_line_break, on_selection_change
  • MenuItemButton: autofocus, overflow_axis, semantic_label
  • Tabs: label_padding, label_text_style, padding, splash_border_radius, unselected_label_text_style, on_click
  • and lot of new classes (enums, dataclasses, events)…

Enhancements

  • Better string output of Events when printed
  • Image.filter_quality now has a default of FilterQuality.MEDIUM (previously FilterQuality.LOW), which is a better default for downscaled images.
  • Geolocator control has been improved to support location streaming through the newly added on_position_change event. When defined, you will be able to "listen" to location changes as they happen.
  • When AppBar.adaptive=True and the app is running on an Apple platform, the AppBar.actions controls are now wrapped in a Row, then displayed. Before this, only the first item of AppBar.actions list was displayed.
  • The Markdown control has been significantly improved. It can now display SVG images and be much more customized.
  • A very requested feature was the ability to set a background image or gradient for the application. In #3820, we made this possible and easy to use.
  • rtl (right-to-left) property has been added to more controls (NavigationRailDestination, NavigationRail, AppBar, CupertinoAppBar, and NavigationDrawer ) to improve support for right-to-left text directions.
  • Introduced --no-rich-output flag (only in flet build command for now) to make it possible to disable rich output (mainly emojis) in the console. More information in #3708.
  • Typing has been significantly improved, particularly for event-handler properties. In modern IDEs like PyCharm and VSCode, you can now easily determine the type of an event handler's argument by simply hovering over the event in the control. Additionally, the IDE will highlight errors when you attempt to access a non-existent property on the event handler argument, ensuring more robust and error-free code.

Bug Fixes

The below issues were successfully fixed:

  • #3769: InputFilter clears the TextField text content when an invalid character is entered
  • #3770: Theme.floating_action_button_theme non existent
  • #3734: Ensure Dropdown.alignment is respected.
  • #3730: UnicodeEncodeError raised when packaging on WindowOS
  • #2160: Markdown control can't render svg images
  • #2158: Markdown broken when an image is not found
  • #3679: Broken Dismissible
  • #3670: Switch.height and Switch.width not respected
  • #3612, #3566: Broken OnScrollEvent
  • #3564: Broken TextField.capitalization
  • #3649: CupertinoPicker jumps-scroll on some platforms
  • #3557: Impeller causes blank screen on mac Intel
  • #3574: Geolocator not working on Android devices
  • #3505: WindowEventType doesn't contain fullscreen all events

Thanks to all those who reported them!

Deprecations

All deprecated items from this release will be removed in version 0.27.0.

  • ThemeVisualDensity is deprecated and has been renamed to VisualDensity
  • CupertinoButton: disabled_color is deprecated and has been renamed to disabled_bgcolor, which better reflects its use
  • Markdown: code_style is deprecated and should now be accessed as code_style_sheet.code_text_style
  • Container: image_fit, image_opacity, image_repeat, image_src and image_src_base64 are deprecated and should now be accessed from image which is of type DecorationImage

Breaking Changes and Migration

Tooltip

The Tooltip class is no more a Flet control and is from now on a simple Python dataclass. The tooltip property (available in almost all controls) now supports both strings and Tooltip objects.

Below is how to migrate:

# before
page.add(
ft.Tooltip(
message="This is tooltip",
content=ft.Text("Hover to see tooltip"),
padding=20,
border_radius=10,
)
)

# after
page.add(
ft.Text(
"Hover to see tooltip",
tooltip=ft.Tooltip(
message="This is tooltip",
padding=20,
border_radius=10,
)
)
)

TextField InputFilter

We modified how InputFilter.regex_string is internally handled. As a result of this, you (might) now have to anchor your regex pattern. This simply implies using start (^) and end ($) regex anchors. For example: r"[0-9]" now becomes r"^[0-9]$". Using this new string will lead work as expected and only numbers/digits will be allowed, but you might notice another issue: the last character of the text field cannot be deleted. To resolve this, you need to add an asterisk (*) in the regex which in this case will simply mean "match zero or more digits (including an empty string)". The new regex now becomes r"^[0-9]*$". To ease this migration, you can use an AI tool with the following simple prompt: "update the following regex pattern: #### ensuring that the entire string matches the pattern and it allows for an empty string".

Event-Handler subscription

The possibility to "subscribe" more than one callback to an event handler has been removed, as this was somehow biased (was only possible on some, and not all). Below is a simple example:

import flet as ft

def main(page: ft.Page):
def print_one(e):
print("1")
def print_two(e):
print("2")
def print_three(e):
print("3")
c = ft.Container(
bgcolor=ft.colors.random_color(),
width=300,
height=300,
)

# subscribe callbacks
c.on_tap_down = print_one
c.on_tap_down = print_two
c.on_tap_down = print_three
page.add(c)

ft.app(main)

In the above code, we subscribe multiple callbacks to the Container.on_tap_down event. Prior to Flet version 0.24.0, running this code and tapping on the Container, you will see all the callbacks getting called ("1", "2" and "3" are printed out). From Flet version 0.24.0 going forward, one event = one callback. Meaning only the lastly subscribed callback will get executed ("3" is printed out) So, if you still want the final output to resemble the first one you can simply create one callback which calls the others:


def main(page: ft.Page):
#....

def print_all(e):
print_one(e)
print_two(e)
print_three(e)

c = ft.Container(
bgcolor=ft.colors.random_color(),
width=300,
height=300,
on_tap_down=print_all,
)

# OR
c.on_tap_down = print_all

Conclusion

As you can see, we made a lot of changes in this release and as usual, your feedback is highly welcomed!

Upgrade to Flet 0.24.0, test your apps and let us know how you find the new features we added. If you have any questions, please join Flet Discord server or create a new thread on Flet GitHub discussions.

Happy Flet-ing! 👾

Flet v0.23.0 Release Announcement

· 3 min read
Henri Ndonko
Flet Contributor and Maintainer

We are excited to announce the release of Flet 0.23.0. It is a big release with many new features and bug fixes.

New Controls

New Properties

Error Handling

PEP 20 (Zen of Python): Errors should never pass silently.

Several devs reported that, on some occasions, a control might visually break without clear information on what caused the break.

For example, in issue #3149, @base-13 mentioned that "in a DataTable if the number of columns is less than the number of datacells in any row it will grey out whole table without throwing error".

Knowing this, we added more assertion-checks in most of the controls, such that, when you provide them with a wrong value, an AssertionError is raised with a very clear message of what was wrongly done.

If you find out that some checks are still missing, please point them out so they can be addressed.

Command Line (CLI) Output

The output of the flet build command has been prettified.

Also, a new option has been added --show-platform-matrix which displays a table containing the build platform matrix, which has header columns "Command" (possible build commands) and "Platform" (the device you should use with the respective command).

Furthermore, when the targeted platform can't be built on your device, a table displaying the build platform matrix is shown with an informative message.

Breaking Changes

While doing "Error Handling" mentioned above, we had to mark some important properties as required.

The following properties are now "required" (must be provided and visible) when creating an instance of their classes:

Bug Fixes

The below issues were successfully fixed:

  • #3144: ScrollbarTheme.thickness value not respected when not interacting with
  • #3072: High-resolution videos play laggy on Android TV devices.
  • #3023: (Regression) Some LineChart colors not visually respected
  • #2989: Color of Dropdown when disabled doesn't reflect its disabled state
  • #1753: Markdown code block not selectable
  • #3097: Hot-reload occurs when a file is opened
  • #1647: Container.theme_mode not honoured when Container.theme=None
  • #3064: Container.on_tap_down not called when Container.on_click=None

Special Thanks to the dynamic Flet community for reporting all the issues they encountered. We keep working hard on solving the remaining ones.

Deprecations

  • All the Page.window_*** properties are now deprecated and moved to Page.window property, which is of type Window. To migrate, simply use change window_ to window. as seen below:

    # before 
    page.window_height = 200
    page.on_window_event = lambda e: print(e.type)

    # now
    page.window.height = 200
    page.window.on_event = lambda e: print(e.type)
  • SafeArea.minimum is deprecated and has been renamed to minimum_padding

  • MaterialState enum is deprecated and has been renamed to ControlState

  • NavigationDestination is deprecated and has been renamed to NavigationBarDestination

Also, the deprecation policy has been modified. While Flet is pre-1.0, all deprecations will be removed from the API after the next 3 releases. So the above deprecations made in v0.23.0 (and all the other deprecations made in the previous versions), will be removed in v0.26.0.

That's it! :)

Upgrade to Flet 0.23.0, test your apps and let us know how you find the new features we added. If you have any questions, please join Flet Discord server or create a new thread on Flet GitHub discussions.

Happy Flet-ing!

Flet at PyCon US 2024

· 2 min read
Feodor Fitsner
Flet founder and developer

Last week we attended PyCon US in a beautiful city of Pittsburgh, PA!

I've been on many conferences, but at PyCon I was amazed by the spacious venue, flawless event organization, high-quality content and welcoming community 😎, ...and good food 🍔!

We met a lot of great people and, especially, wonderful people from Beeware (hello Russell, Malcolm and Russell 👋). They did a great job of popularizing Python on mobile and advocating the addition of iOS and Android to the list of supported platforms in the next release of Python 3.13 🎉!

We enjoyed good talks and inspirational key notes, learned new things, enjoyed the city. Lightning talks (short 5-minute presentations) were real fun!

Oh, I saw Guido van Rossum (The Creator of Python himself, in case you didn't know 😅) at Microsoft booth, but didn't have a chance to take a picture with him as there was a line up 😉.

As first time attendees we did't do talks or presentations, but watched and learned instead. We plan to present next year 🤞.

Next PyCon US is going to be at the same place. Will come again and hope to see more of you there!

Flet packaging update

· 7 min read
Feodor Fitsner
Flet founder and developer

The problem

When you package your Flet program in Python to run on a mobile device (or desktop) the resulting bundle (.apk, .ipa, .exe, .app) contains your Python program, Python interpreter and Python Standard Library.

If your program uses only Python standard library then packaging process is relatively easy - Flet zips your code and combines Flutter app together with Python interpreter and standard library both compiled for the target platform: Android or iOS.

However, problems may arise when your Flet program uses third-party packages, with thousands of them published on PyPI or Conda.

There are two kinds of third-party packages:

Pure-Python packages

A "pure-Python" package is a package that only contains Python code, and doesn't include extensions written in C, C++, Rust or other languages. You only need a Python interpreter and the Python Standard Library to run a pure-Python package, and it doesn't matter what your OS or platform is.

Examples of such packages: httpx, click, rich, requests.

To verify if the package is pure, find that package on PyPI and navigate to its "Download files" page. If under "Built distribution" section there is only one wheel ending with -py3-none-any.whl then most probably it's a pure Python package that will work "as is" on any device with Python.

We say "probably" because that pure package could depend on a non-pure package which brings you to the next section. For example, pydantic is a pure package, but to work properly it requires pydantic-core non-pure package written in Rust.

Non-pure Python packages

A "non-pure Python" package is one that is fully or partially written in C, C++, Rust, or another language and must be compiled to machine code for the platform on which it will run.

Examples of such packages: cryptography, opencv-python, numpy, msgpack.

On "Download files" page of non-pure package you will find a bunch of wheels pre-built for various platforms: macOS, Windows, Linux.

When you run pip install <package> pip tries to find a wheel for your specific platform and Python version looking at wheel suffixes that include that information.

It's a courtesy of package developer to provide pre-compiled wheels for multiple platforms. There could be missing wheels for some platforms, or no wheels at all - just .tar.gz under "Source distribution" with package sources.

Building package from sources is hard

To install a package with source distribution only, pip will attempt to build non-Python code on your machine using installed compilers, linkers, libraries, and SDKs. However, this process can be lengthy and error-prone. The compiled code base might be large, and your machine could lack the required libraries or toolchains.

No wheels for iOS and Android yet

There are no pre-built wheels for iOS and Android on PyPI and PyPI's validation process won't allow package developers to upload them anyway as both iOS and Android are not officially supported platforms in Python.

There is a process (PEP 730 and PEP 738) to add official support for iOS and Android to Python 3.13, so, hopefully, the developer experience will improve.

Package dependencies

Pure-Python packages can import or depend on non-pure packages and you should keep that in mind while packaging your Flet app to run on a mobile device.

For example, supabase package, to access Supabase API, is a pure package which depends on pydantic package which is also pure Python package. In its turn pydantic package depends on pydantic-core which is a non-pure package written in Rust. Thus, to run your Flet app using Supabase API the packaging process should be able to find a pre-build wheel for your target platform. If PyPI doesn't have that wheel then it could be either Flet developers, building that wheel on their servers and hosting it somewhere, or you, building that wheel on your own machine.

To see a dependency graph for a package you can use pipgrip.

Run it with --tree option to get a tree view of dependencies:

$ pipgrip --tree fastapi

fastapi (0.110.3)
├── pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4 (2.7.1)
│ ├── annotated-types>=0.4.0 (0.6.0)
│ ├── pydantic-core==2.18.2 (2.18.2)
│ │ └── typing-extensions!=4.7.0,>=4.6.0 (4.11.0)
│ └── typing-extensions>=4.6.1 (4.11.0)
├── starlette<0.38.0,>=0.37.2 (0.37.2)
│ └── anyio<5,>=3.4.0 (4.3.0)
│ ├── idna>=2.8 (3.7)
│ └── sniffio>=1.1 (1.3.1)
└── typing-extensions>=4.8.0 (4.11.0)

Current approach

We released the first version of packaging 4 months ago and since then, we have realized that the initial approach has multiple flaws and should be improved.

When you run flet build apk with the current Flet version it downloads Python runtime with standard library both pre-built for Android (or iOS if ran with flet build ipa).

For non-pure packages, like numpy, Flet is asking you to build those packages by yourself using "Python for Android" (p4a) tool from Kivy and then provide a path to "p4a" distributive where those pre-build packages could be found.

This is problem #1 - you are forced to struggle with a complicated process of installing "p4a" tool and compiling Python modules on your machine.

Problem #2 - all packages from p4a's dist directory will be included into a final application bundle - it could contain non-relevant packages and other junk.

Problem #3 - non-pure packages must be built before running flet build command. You have to analyze all dependencies of your app and separate what must be built with p4a.

Problem #4 - p4a "recipes" to build packages could be either very old or missing. You hope that older version of the package works with your app, try authoring a "recipe" and hope it works or submit a request for new recipe in Kivy repository.

When you're done with building non-pure packages using p4a, Flet requires you to specify only pure packages in requirements.txt which doesn't work if pure package directly or indirectly depends on non-pure (see example above) - this is problem #5. There is a recent example of this problem: flet build replaces flet with flet-embed in requirements.txt, but it's unable to know if there is a 3rd-party package depending on flet, thus both flet-embed and non-suitable-for-mobile flet are installed. This is not a solution, but a hack!

Packaging 2.0

In the next iteration of Flet's packaging implementation, we are going to move away from Kivy and replace it with Mobile Forge. Mobile Forge has been created by Beeware team based and their experience with Briefcase and Chaquopy. Mobile Forge is a clean-room implementation of a packaging tool for binary Python packages which is relies on crossenv.

The main promise of Mobile Forge with crossenv is that most existing non-pure Python packages will be able to compile for iOS and/or Android by simply adding a recipe with meta.yaml file only, without requiring any hacks or patches.

We are going to use Mobile Forge to pre-build the most popular non-pure Python packages for iOS and Android and host them in our own public repository. You will be able to use that tool to build and contribute other packages, non present in our repository.

We've created a new "Packages" category in Flet discussions where you can post, vote and discuss requests for non-pure (native) Python packages that work with Flet (check rules before posting there). Flet's goal is to provide the most comprehensive catalog of pre-built Python packages and make the process of adding new packages as friendly and transparent as possible.

The new version of flet build will use a custom-made virtual pip index. This index will analyze dependencies, detect non-pure packages, and offer to pip mobile packages. For all other packages, it will fall back to PyPI.

The new packaging will be hopefully available in a few weeks. While we are working we encourage you to visit Packages and see if the package you need is there. Submitting a request or voting for existing package will help us to prioritize package "recipes".

Thank you!

Controls and theming enhancements

· 5 min read
Henri Ndonko
Flet Contributor and Maintainer

One month after the release of Flet 0.21.0, we are excited to announce the release of Flet 0.22.0.

This release comes with a lot of enhancements, bug fixes, and deprecations:

Enhancements

This was one of the main concerns while coming up with this release. Two types of enhancements were made:

Controls Enhancement

We went through the long list of already-present controls and exposed, where possible, more properties - PR #2882. This will grant you more power/control over the Flet Controls you use in your awesome applications.

Below is the complete list:

  • AppBar: elevation_on_scroll, exclude_header_semantics, force_material_transparency, is_secondary, shadow_color, surface_tint_color, clip_behavior, title_spacing, toolbar_opacity, title_text_style, toolbar_text_style, shape
  • AlertDialog: action_button_padding, clip_behavior, icon_padding, shadow_color, surface_tint_color
  • Banner: content_text_style, margin, elevation, divider_color, shadow_color, surface_tint_color, on_visible
  • CupertinoListTile: leading_size, leading_to_title
  • CupertinoSegmentedButton: click_color
  • CupertinoSwitch:on_label_color, off_label_color
  • CupertinoTimerPicker: item_extent
  • Chip: surface_tint_color, color, click_elevation, clip_behavior, visual_density, border_side
  • Divider: leading_indent, trailing_indent
  • ExpansionTile: dense, enable_feedback, visual_density
  • Card: clip_behavior, is_semantic_container, show_border_on_foreground, variant
  • Checkbox: border_side, semantics_label, shape, splash_radius, is_error, visual_density, mouse_cursor
  • CircleAvatar: on_image_error
  • DataTable: clip_behavior
  • DatePicker: on_entry_mode_change
  • Draggable: on_drag_complete, on_drag_start
  • DragTarget: on_move
  • Dropdown: fill_color, hint_content, icon_content, elevation, item_height, max_menu_height, icon_size, enable_feedback, padding, icon_enabled_color, icon_disabled_color, on_click
  • ElevatedButton: clip_behavior
  • FloatingActionButton: clip_behavior, enable_feedback, focus_color, foreground_color, disabled_elevation, elevation, focus_elevation, highlight_elevation, hover_elevation, mouse_cursor
  • GridView: cache_extent, clip_behavior, semantic_child_count
  • IconButton: alignment, disabled_color, focus_color, enable_feedback, hover_color, padding, splash_color, splash_radius, focus_color, mouse_cursor, visual_density
  • Image: exclude_from_semantics, filter_quality
  • ListTile: enable_feedback, horizontal_spacing, min_leading_width, min_vertical_padding, selected_color, selected_tile_color, style, title_alignment, icon_color, text_color, shape, visual_density, mouse_cursor, title_text_style, subtitle_text_style, leading_and_trailing_text_style
  • ListView: cache_extent, clip_behavior, semantic_child_count
  • NavigationBar: animation_duration, overlay_color
  • NavigationDrawerDestination: bgcolor
  • NavigationBarDestination: bgcolor
  • NavigationRail: selected_label_text_style, unselected_label_text_style
  • NavigationRailDestination: indicator_color, indicator_shape
  • Option: alignment, on_click
  • OutlinedButton: clip_behavior
  • Page: locale_configuration
  • PopupMenuItem: height, padding, mouse_cursor
  • PopupMenuButton: bgcolor, clip_behavior, elevation, enable_feedback, icon_color, shadow_color, surface_tint_color, icon_size, padding, splash_radius, shape, on_open, on_cancel
  • ProgressBar: border_radius, semantics_label, semantics_value
  • ProgressRing: semantics_label, semantics_value, stroke_cap, stroke_align
  • Radio: focus_color, hover_color, overlay_color, splash_radius, toggleable, visual_density, mouse_cursor
  • SearchBar: keyboard_type, view_surface_tint_color, autofocus
  • SelectionArea: on_change
  • Slider: interaction, overlay_color, mouse_cursor, secondary_track_value, secondary_active_color
  • Stack: alignment, fit
  • SnackBar: clip_behavior, shape, on_visible, action_overflow_threshold
  • Switch: hover_color, splash_radius, overlay_color, track_outline_color, mouse_cursor
  • Tabs: divider_height, enable_feedback, indicator_thickness, is_secondary, mouse_cursor, clip_behavior
  • TextField: fill_color, hover_color
  • TimePicker: orientation, on_entry_mode_change
  • Tooltip: enable_tap_to_dismiss, exclude_from_semantics
  • VerticalDivider: leading_indent, trailing_indent

If you however feel that something lacks and should be added, don't hesitate to let us know.

Check out the article I wrote concerning Page.locale_configuration here.

Theme Enhancements

The Theme class which is used for application theming in light and dark mode has equally been further enhanced. Lots of new themes were introduced - PR #2955.

See the Theming Guide here.

Rive Animations

Rive is a very popular real-time interactive design and animation tool. The newly introduced Rive Control allows you to load and visualize any Rive animation in your applications.

The animation's source (Rive.src) can either be a local asset file or a URL - as usual, it all depends on your needs.

Parent Control

As requested in #952, the ability to access the parent of any control has been added: Control.parent.

Read more on it here.

Bug Fixes

The below issues were successfully fixed:

  • #2560 - Dropdown.bgcolor was not visually respected
  • #2740 - CircleAvatar not working with local asset images
  • #2781 - 'FletSocketServer' Error raised on Linux
  • #2826 - PopupMenuItem.data not respected
  • #2839 - ExpansionTile.initially_expanded had no visual effect
  • #2867 - PopupMenuButton had an always-visible tooltip of "Show menu"
  • On some Python versions, you might have seen a RuntimeError('Event loop is closed') which usually shows up when closing the app's window. The Python-dev team fixed this asyncio-related issue recently, but this fix is only present in the versions released from the year 2024. So if you face this issue, please download one of the latest Python releases and replace the one used in your environment.

Special Thanks to the dynamic Flet community for reporting all the issues they encountered. We keep working hard on solving the remaining ones.

Deprecations

As previously mentioned in the announcement concerning Flet v0.21.0, all deprecations will be completely removed from the API in version 1.0 - so you have enough time to update your apps.

You must not completely memorize what has been deprecated as we've added DeprecationWarnings which will be shown directly in your console (without breaking your app).

Documentation

The Flet documentation has been reorganized to ease navigation (especially for beginners/new users).

Upgrade to Flet 0.22.0, test your apps and let us know how you find the new features we added. If you have any questions, please join Flet Discord server or create a new thread on Flet GitHub discussions.

Happy Flet-ing!