Flutter apps in Python — Flet
Flet is a framework that allows building interactive multi-user web, desktop and mobile applications in your favorite language. You build a UI for your program with Flet controls which are based on Flutter by Google. Flet does not just “wrap” Flutter widgets, but adds its own “opinion” by combining smaller widgets, hiding complexities, implementing UI best-practices, applying reasonable defaults. At the moment you can write Flet apps in Python. — flet
Flet module
pip install fletInstallation specific to Linux and WSL.
After installing the module we could simply import flet and start building our App.
Getting started
Hello world
The simple Hello World! app would look like,
import flet as ft
def main(page: ft.Page):
page.title = "Hello world App"
page.add(ft.Text("Hello, Flet World!"))
ft.app(target=main)The app will be started in a native OS window.
If you want to run the app as a web app, then
ft.app(target=main, view=ft.WEB_BROWSER)Controls
User interface is made of Controls (aka widgets). To make controls visible to a user they must be added to a
Pageor inside other controls. Page is the top-most control. Nesting controls into each other could be represented as a tree with Page as a root.Controls are just regular Python classes. Create control instances via constructors with parameters matching their properties. — flet controls
Controls in our Hello world code
t = ft.Text("Hello World!")To display the controls on the page that we defined, we need to append it to the Page controls and update the page.
page.controls.append(t)
page.update()But luckily we have page.add() which does the same.
page.add(t)Whenever we made change to the controls, we need to use page.update() method to see the changes in the UI.
Get Logesh’s stories in your inbox
Join Medium for free to get updates from this writer.
Example of changing the value of the text.
import flet as ft
from time import sleep
def main(page: ft.Page):
t = ft.Text()
page.add(t) # it's a shortcut for page.controls.append(t) and then page.update()
for i in range(10):
t.value = f"Step {i}"
page.update() # updating the change
sleep(1)
ft.app(target=main)Whatif the page.update() is removed, simply the change that we made to the text won’t be reflected in the UI.
Flet almost has all the Flutter widgets in the name of Controls.
Next step
So far we have seen the introduction to Flutter Apps in Python using Flet framework, as a next step I will attach the links to the Flet docs to get to know more about Flet.
At the time of writing this article, the Flet doesn’t supports standalone Mobile apps. It uses Server-driven UI (SDUI).
Hope this article introduces you with the Flet.
Happie Flet!!!

