-
Notifications
You must be signed in to change notification settings - Fork 536
Building multi‐platform apps in Python powered by Flutter
Flet allows Python developers to easily add awesome user interface to their apps and package them to run on web, desktop and mobile devices - all with a single code base.
Why another UI library for Python? Unlike other UI frameworks for Python Flet does not implement UI widgets from scratch or wrap native platform controls, but, instead, it relies on Flutter framework by Google. Initially born as a mobile framework, Flutter recently got a serious push from Google with added support for web and desktops.
Flet brings the power of Flutter to Python developers - for free. UI developed with Flet looks aesthetically pleasant, it's adaptive, responsive, localizable and accessible. Flet provides more than 100+ controls and could be easily extended with a wide array of 3rd-party packages and plugins provided by a vast Flutter ecosystem.
How easy to use Flet?
Flet UI is built of stateful controls which fire events triggered by user interaction. In event handlers developer updates control properties thus mutating user interface.
Here is a simple Flet program which prompts user for a name and outputs the greeting:
import flet as ft
def main(page: ft.Page):
def btn_click(e):
page.clean()
page.add(ft.Text(f"Hello, {txt_name.value}!"))
txt_name = ft.TextField(label="Your name")
page.add(txt_name, ft.ElevatedButton("Say hello!", on_click=btn_click))
ft.app(main)
To run the code above as a desktop app:
flet run app.py
To run the same app as a web app:'
flet run --web app.py
To test the app on iOS or Android there is "Flet" app in both App Store and Google Play that could be installed on a user device.
[IOS AND ANDROID SCREENSHOTS]
How does Flet work?
Flet app consists of "backend" and "frontend" parts. Backend is a Python runtime running user app and frontend is a Flutter app rendering the user interface. Frontend and backend are communicating via JSON protocol. Every change to app controls is encoded into JSON and transmitted to a frontend. User interactions on a frontend are transmitted as control events to backend.
[DIAGRAM]
For desktop and mobile both backend and frontend are parts of the same app (embedded Python runtime inside a Flutter host) and for web Flutter frontend is running in the browser and communicates with Python backend on the server via WebSockets.
learned, and any recommendations
Created framework.
Developers like Flutter, developers like Flet.
A lot of challenges to solve. Mainly packaging for mobile.
Work with Kivy and Beeware, PEPs to make iOS/Android part of Python standard - important for our project.