Skip to content

Add utility functions to FletXPage for faster development #85

@Einswilli

Description

@Einswilli

Description:
Currently, when working with FletXPage, developers need to access ft.page directly for common actions like showing a loader, a snackbar, or a dialog.
This can slow down development and make code less clean.

Proposed Solution:
Add built-in utility methods to FletXPage that act as shortcuts for these actions:

  1. self.show_loader(message: str, widget: Optional[Control] = None)

    • Displays a popup with a loading message and a ProgressRing by default.
    • Allows passing a custom widget for flexibility.
  2. self.show_snackbar(message: str, duration: int = 3000, widget: Optional[Control] = None)

    • Displays a snackbar directly from a FletXPage.
    • Allows passing a custom widget for flexibility.
  3. self.show_dialog(dialog: Control)

    • Opens dialog boxes without needing to call ft.page manually.

Example Usage:

class MyPage(FletXPage):
    ...

    def on_load(self):
        self.show_loader("Loading data...")
        # simulate some work...
        self.show_snackbar("Data loaded successfully")
    
    def on_error(self):
        self.show_dialog(
            AlertDialog(title=Text("An error occurred"), on_dismiss=self.close_dialog)
        )
    
    ...

Benefits:

  • Speeds up development.
  • Makes code cleaner and more readable.
  • Improves developer experience by reducing boilerplate code.

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions