-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Re-design Python controls and their Flutter counterparts #4300
Comments
Would be nice if all def, could be converted to async def. Even a lot of controls won't work properly without their corresponding async method. The issue is cannot call async methods within an init in a class. Since controls are built in init method causes issues. Sure you could hack around this in init method by doing something like: Maybe building the controls for the page could be placed in an async def builder() function in the class instead. Another note is python 3.13 removing the gil as experimental currently, threading may come into picture very shortly if someone wants to run a long running CPU intensive task utilizing separate threads/cores in their app. This may become a common place in future when everyone running pytorch in background threads either training models or running inference, without having to fork a subprocess to force it to use more cores. |
@syleishere they are mostly async now. Could you give some specific examples? |
I can give you a live example for playing with controls in an advanced fun way(tested in chrome) Code: Here route is changed to Page1App
|
That's just an example, but there are lots more, like calling an async function to update a slider, calling an async function to get IP address, or even client storage routines only seem to work for me with their _async counter parts. Or here is a small example snippet from a nav bar trying to hack around calling an async call to change theme for app:
|
I'm curious why you decided to go with redux though. Honestly I remember building my first flutter app and I absolutely hated the state management system until I found: https://pub.dev/packages/get Was a lifesaver, I remember sticking everything I wanted to keep state of in a controller.dart file and every other dart file it was as simple as: import 'package:get/get.dart'; import './controller.dart'; final Controller c = Get.find(); For example snippet of my old code from controller.dart from 5 years ago:
Example snippet of using it from a dart file accessing c.song0 from controller.dart:
Just my 2 cents anyways, cut boiler plate code down dramatically making it a somewhat enjoyable experience lol. |
Because I was coming from React and Redux for Dart was like "oh, nice!" :) |
Fair enough, snack bar is more beautiful in GetX though lol :) |
The problem
.update()
method coming from an old web-only Flet design.The solution
@dataclass
for UI controls on Python side..update()
method, switch to a single-threaded UI model.Page
toApp
.ChangeNotifier
for controls on Dart side andInheritedNotifier
orListenableBuilder
widgets to re-build UI when control props change.Additional details
Python control classes could be
@dataclasses
and look like this:Example usage:
Base classes
EmbedJsonEncoder
The text was updated successfully, but these errors were encountered: