I hate boilerplate code. I hated it all my life. I made so many steps to remove this mental parasites far from me. And now, with Flet and Django I'm so close to get my ideal. For this moment I made as PoC a clone of a standard Flet ToDo application. All what I change is write all directly inside Django. Flet code is run directly on the backend, so we not need any dedicated communication layer. Next what I'm done is generic data table control. This is a simple control able to create a data table for any Django model. All with searching and sorting.
Install python package:
$ pip install flet-django
INSTALLED_APPS += ['flet_django']
pip install Django
django-admin startproject test_flet_django
cd test_flet_django
python manage.py migrate
pip install flet
pip install flet-django
echo "INSTALLED_APPS += ['flet_django']" >> test_flet_django/settings.py
import flet as ft
from flet_django.pages import GenericApp
main = GenericApp(controls=[ft.Text("Hello World!")])
python manage.py run_app
Let create a simple flutter view example in file main_app.py:
import flet as ft
from flet_django.views import ft_view
def home(page):
return ft_view(
page,
controls=[ft.Text("Hello World!")],
app_bar_params=dict(title="ToDo app")
)
Flutter view can be assigned to route by Generic App's urls parameter, or as a target for navigation:
import flet as ft
from django.urls import path
from flet_django.views import ft_view
from flet_django.pages import GenericApp
from flet_django.navigation import Fatum
def home(page):
return ft_view(
page,
controls=[ft.Text("Hello World!")],
app_bar_params=dict(title="ToDo app")
)
destinations = [
Fatum(
route="/",
icon=ft.icons.HOME,
selected_icon=ft.icons.HOME_OUTLINED,
label="home",
nav_bar=True,
action=True,
nav_rail=False
),
]
urlpatterns = [
path('', home, name="home")
]
main = GenericApp(
destinations=destinations,
urls=urlpatterns,
init_route="/"
)
python manage.py run_app --view flet_app_hidden
open http://ala.hipisi.org.pl:8085
cd frontend
flutter run --dart-entrypoint-args http://94.23.247.130:8085
python run.py
You can run repository's project as example of usage. Working demo is here.