-
-
Notifications
You must be signed in to change notification settings - Fork 180
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
Hooks don't match flutter Widget #452
Comments
At least for hooks, the combination of the two is messy. class Example extends HookWidget {
const Example({super.key});
@override
Widget build(BuildContext context) {
final innerState = useState("name");
return Text(innerState.value);
}
} Example is Stateless, why it hold a inner state. Stateless Widget should pure and only dependency constructor args. The fact that method-widget might not enable a full widget-tree with associated system optimizations is, in my view, an acceptable tradeoff for using hooks. If we're not comfortable with that, then we should avoid using hooks. The design philosophies of these two are contradictory. Maybe hooks not match with flutter |
Hooks smooth out the differences between stateless and stateful. So it is very confusing whether your Widget has state or not. hooks's definition of state is completely out of the flutter Widget system |
Is your feature request related to a problem? Please describe.
Flutter widget is base on class extends. this Widget System is not match with hooks. SwiftUI and Compose, by contrast, have completely discarded class. their hooks no sense of violation. https://github.com/ra1028/swiftui-hooks
https://github.com/junerver/ComposeHooks
Trying to shoehorn hooks into an class inherited Widget is awkward and doesn't work well. Classes provide their own clear lifecycle, such as initState and dispose, and adding hooks on top only creates a tangled mess, driving up development costs. Users will find it very confusing.
Hooks work best when used in functions; we should completely move away from inheritance.
Describe the solution you'd like
this is a Compose-Style, only use method to define widget instead of class
Maybe we can expose HookBuilder only. force user write method-widget.
in #441, The real reason is just that he's using hooks in a class, which is causing some confusion. he changed controller, but the widget not rebuilding, if he use method-widget. he must define controller like this. Because method-widgets require useState for controllers, controller changes will always cause a rebuild.
The text was updated successfully, but these errors were encountered: