Closed skillkrio closed 1 year ago
Say you made a mixin for creeating + disposing a TextController:
mixin MyMixin on State<StatefulWidget> {
final controller = TextController();
@override
void dispose() {
controller.dispose();
super.dispose();
}
}
That works fine for creating one controller. But if you want to create two of them, you can't apply the mixin twice to create two independent controller:
class MyState extends State<MyWidget> with MyMixin, MyMixin {
}
Whereas with hooks, the equivalent would be using useTextEditingController
twice:
Widget build(context) {
final controller1 = useTextEditingController();
final controller2 = useTextEditingController();
}
Wonderful Example. Thanks alot @rrousselGit .
Dart mixins can partially solve this issue, but they suffer from other problems:
I didn't understand the above one. Can you explain it further an example would be appreciated @rrousselGit