Replies: 4 comments 11 replies
-
The single approach solve the Theme problem and it will probably be of great use when devs rely on their own InheritedWidget but I rather prefer your adapter approach. It may gather in one place all default Flutter requirements. I'm also interested to see if there a place for animation in this wrapper of if it required another specific piece of code. At the end as a dev I would like to easily subscribe to explicit Flutter signals. We may have to introduce common ancestors widgets |
Beta Was this translation helpful? Give feedback.
-
I think it's not such a bad idea to include a Root widget to track signal mutations and enable more efficient updates. A package that does this and uses distributed states is "asp" or "rx_notifier". What really frustrates me is the need to use builders for this granular reactivity. As more builders and widgets are added, the signals approach will look more like traditional approaches like MobX and others. This will make its adoption difficult, with questions like "what's the difference between a value notifier or mobX)"? That's why I believe that solid_dart didn't grow, as it already used builders from the beginning. |
Beta Was this translation helpful? Give feedback.
-
Now that I have had time to think about it more, I don't think we need a widget at all. In fact just a single builder could do the work. final theme = signal(ThemeData());
class App ... {
...
@override
Widget build(BuildContext context) {
return MaterialApp(
...
builder: (context, child) {
theme.value = Theme.of(context);
return child;
},
home: ...
);
}
}
...
class Child ... {
final bodyLarge = computed(() => theme.textTheme.bodyLarge);
@override
Widget build(BuildContext context) {
return Text('Hello', style: bodyLarge);
}
} So instead I think documentation would be the better solution here. Also since signal skip updates if the value is the same this would also be a noop on objects that haven't changed and override ==. |
Beta Was this translation helpful? Give feedback.
-
Related to the mentioned observed For more info, see flutter/flutter#89127 (comment) |
Beta Was this translation helpful? Give feedback.
-
I have noticed in when using the
Watch
widget that if any inherited elements are used from the context it can cause unnecessary rerenders.For some models like Theme and Media it would be nice to pull it out of the tree and map to a global or local signal. This of course would break any overrides but this widget could be used where you want to break out a model.
Consider the following:
This would rebuild the child forever if called even once. But really we want to rebuild when bodyLarge changes the value.
I wrote the following mapper:
That can be used to pull the model out of the tree:
Now the
Child
will only rebuild when the selector changes and does not react to anything else. This also means there is one subscriber to the Theme class too.Feedback
Really not sure what to call this new widget that would be included in
signals_flutter
.Also maybe a MultiAdapter could be done to map to multiple signals on models from the context?
Related Flutter Issues
removeDependency
on theInheritedElement
flutter/flutter#128432Beta Was this translation helpful? Give feedback.
All reactions