Skip to content

A simple library makes flet more stateful

License

Notifications You must be signed in to change notification settings

nnko0o/stateful-flet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stateful Flet Library

State Management for Flet

Stateful Flet

Flet library, makes flet more stateful BY adding state management close to React Easy, Speed and Strong

Installation (BETA)

Install From Git Branch:

pip3 install -U git+https://github.com/nnko0o/stateful-flet.git

Basic Usage

import flet as ft
from stateful_flet import StatefulUC

class App(StatefulUC):
    def __init__(self):
        super().__init__()
        # make new state and make the value is `True`
        self.myState = self.state(True)

    def build(self):
        self._content = ft.Column(
            controls=[
                ft.ElevatedButton(
                    text     = 'State: '+str(self.myState.get()),
                    # when the user click, thge state wull change
                    on_click = lambda e: self.myState.set(lambda v: not v),

                    # Color will changes when state change and re-render the page
                    bgcolor  = ft.colors.BLACK if self.myState.get() else ft.colors.BLUE_GREY_800 ,
                    color    = ft.colors.WHITE24 if self.myState.get() else ft.colors.BLUE_GREY_50
                )
            ]
        )

        return self._content

def main(page: ft.Page):
    page.vertical_alignment   = 'center'
    page.horizontal_alignment = 'center'
  
    page.add(
        App(page)
    )

if __name__=='__main__':
        ft.app(
            target=main,
        )

Philosophy

flet missing a state management from make it more smoothly
so i get React State Management and make it more pythonic and work perfectly with flet
ِAnd make it fast as possible with minimal use of hardware resources
By remove the multiple loops in the threads in Effect and make it work by add the effect function in the Stateful Objects

TODO:

  • State - work hand by hand with flet.
  • SattfulUserControl(StatdfulUC) - statful control can rerender and make State and Context easy.
  • Effect - simple stateful hook run some function when some Stateful Object changes.
  • Context - State but in multiple StatdfulUC, change from one place, and all place's will be rerender.
  • Add String Docs for all function and classes.
  • Add Full API Reference and Docs for all the library.
  • Make A Class and UI helpers for customize re-rendering for make your application more faster and stable.

Contact Me:

Telegram

About

A simple library makes flet more stateful

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages