A minimal class which generates a Flet application.
Flet is a framework that allows building interactive multi-user web, desktop and mobile applications in your favorite language without prior experience in frontend development [1]. Flet controls are based on Flutter [2].
[1] https://flet.dev
In Flet documentation [3], there does not exist an object oriented approach that generates a Flet application. In this class, I have tried to create a minimal class that generates a Flet application. To do this, we overwrite the __call__
method of a simple class and use this class as an argument for the flet.app
function.
[3] https://flet.dev/docs/quickstart
It is just a boilerplate class, you can directly use it. However you need to install flet module first. You can use the package manager [pip] to install flet with one of these following commands.
pip install flet
pip3 install flet
python -m pip install flet
python3 -m pip install flet
py -m pip install flet
As a first step you should import flet module.
import flet
Then you can edit the name of the class and all the other information required to build your application.
class MinimalFletClass:
def __init__(self):
self.__page = None
def __call__(self, flet_page: flet.Page):
self.__page = flet_page
'''
Create your app here
'''
self.__page.update()
At last you can check if your Python file is called directly or not. If it is, then you can create an instance of MinimalFletClass as:
if __name__ == '__main__':
flet.app(target=MinimalFletClass())
You can find these codes in minimal.py file. Also you can use boilerplate.py file as a more complete starting point for your first application.
Boilerplate Flet Class with dark theme
Boilerplate Flet Class with light theme
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.