Release Notes: Flet Model v0.1.5
Introduces a significant enhancement to the router system with the new decorator-based route registration!
New Features
Decorator-based Route Registration
You can now register routes using the @route
decorator directly on your Model classes:
from flet_model import Model, route
@route('home')
class HomeModel(Model):
# model implementation
This replaces the previous dictionary-based route registration:
# Old way (still supported for backward compatibility)
Router(
{'home': HomeModel(page)}
)
# New way - cleaner and more intuitive
@route('home')
class HomeModel(Model):
# model implementation
Automatic Router Initialization
The Router now automatically initializes when your application starts, eliminating the need for explicit initialization code:
# Old way
def main(page: ft.Page):
Router({'home': HomeModel(page)})
page.go('/home')
# New way
def main(page: ft.Page):
# No router initialization needed!
page.go('/home')
Improved Navigation
The Router now ensures that route handlers are properly registered before navigation occurs, fixing potential race conditions that could lead to blank screens.
Benefits
- Cleaner code: Route definitions are directly attached to their Model classes
- Reduced boilerplate: No need to create Router instances or pass routes in dictionaries
- Better maintainability: Adding or removing routes is as simple as adding or removing decorators
- Improved readability: Route associations are more visible and self-documenting
Migrating to v0.1.5
Migrating to the new decorator-based approach is straightforward:
-
Update to the latest version:
pip install flet-model==0.1.5
-
Replace dictionary-based routes with decorators:
# Before class HomeModel(Model): route = 'home' # model implementation Router({'home': HomeModel(page)}) # After @route('home') class HomeModel(Model): # model implementation # route property is automatically set by the decorator
-
Remove the explicit Router initialization (optional, as it's still supported for backward compatibility)
Documentation
For complete documentation and examples, please refer to the [README](https://github.com/fasilwdr/Flet-Model#readme) and [API documentation](https://github.com/fasilwdr/Flet-Model#usage).