Closed pimvanderheijden closed 1 month ago
Hi Pim,
get_it alone won't update your UI if any of your singletons changes. So either you have to use ValueListenableBuilders or StreamBuilders. Watch_it makes that much easier because you just watch any Listenable, Stream, Future and it will rebuild the widget with the new data? Cheers Thomas Am 31. Mai 2024, 15:23 +0200 schrieb Pim van der Heijden @.***>:
Hi! I got very excited about get_it when I finally worked myself into so much trouble with globals and singletons that I decided to look for a more structured solution. I immediately understood intuitively what it was about and why it meant be added value for my code. With watch_it, however, I'm clueless. Yes I'm looking for a simple state management solution, to remove clutter and organize my code. Yes I could use such a solution probably to optimise some code paths and some rendering. But, does watch_it do any of this? How so? How is watch_it different from the other tools out there? Thanks for clarifying, maybe it will create some nice content for the readme π Cheers π β Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>
Sorry but natively this already requires very little code, right? Whatβs the problem and why does watch_it solve it?
How do do it natively normally? Am 31. Mai 2024, 16:08 +0200 schrieb Pim van der Heijden @.***>:
Sorry but natively this already requires very little code, right? Whatβs the problem and why does watch_it solve it?
On Fri, 31 May 2024 at 15:28, escamoteur @.***> wrote:
Hi Pim,
get_it alone won't update your UI if any of your singletons changes. So either you have to use ValueListenableBuilders or StreamBuilders. Watch_it makes that much easier because you just watch any Listenable, Stream, Future and it will rebuild the widget with the new data? Cheers Thomas Am 31. Mai 2024, 15:23 +0200 schrieb Pim van der Heijden @.***>:
Hi! I got very excited about get_it when I finally worked myself into so much trouble with globals and singletons that I decided to look for a more structured solution. I immediately understood intuitively what it was about and why it meant be added value for my code. With watch_it, however, I'm clueless. Yes I'm looking for a simple state management solution, to remove clutter and organize my code. Yes I could use such a solution probably to optimise some code paths and some rendering. But, does watch_it do any of this? How so? How is watch_it different from the other tools out there? Thanks for clarifying, maybe it will create some nice content for the readme π Cheers π β Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>
β Reply to this email directly, view it on GitHub https://github.com/escamoteur/watch_it/issues/31#issuecomment-2142166771, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFL2SSUE4CWHFZNGPI6VSITZFB3GNAVCNFSM6AAAAABIS2CEW2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBSGE3DMNZXGE . You are receiving this because you authored the thread.Message ID: @.***>
β Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
Ok
class AppState with ChangeNotifier {
String foo = barβ
}
in main() you do
var appState = AppState();
runApp(
ChangeNotifierProvider(
create: (context) {
return appState;
},
child: MyApp(),
),
)
in MyApp's build function you do
@override
Widget build(BuildContext context) {
var appState = context.watch<AppState>();
return Scaffold(
body: Text(appState.foo)
)
}
Now when the value of foo
changes, the Text
gets rerendered.
Ah, you are using Provider. Which isn't a part of the Flutter framework itself. watch_it allows you the same without provider. Am 2. Juni 2024, 14:10 +0200 schrieb Pim van der Heijden @.***>:
Ok class AppState with ChangeNotifier { String foo = barβ } in main() you do var appState = AppState();
runApp( ChangeNotifierProvider( create: (context) { return appState; }, child: MyApp(), ), ) in MyApp's build function you do @override Widget build(BuildContext context) { var appState = context.watch
(); return Scaffold( body: Text(appState.foo) ) } Now when the value of foo changes, the Text gets rerendered. β Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
Ah yes, great that clarifies, thanks.
And why should I use watch_it
instead of provider
?
Ok, that's the interesting question π
Ah yes, great that clarifies, thanks. And why should I use watch_it instead of provider? β Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
get_it
for getting my AppState instance and other helper class instances outside of Widget contexts.provider
I do:
var foo = context.watch<AppState>().foo;
Whereas with watch_it
I would do this for every value I have.
final foo = watchPropertyValue((AppState a) => a.foo);
With cluttering I mean that you have to add a provider widget somewhere in your widget tree You can use the simple 'watch' method to watch a whole object that implements Listenable/ChangeNotifier so you don't have to watch every property separately. Check out the different watch functions Am 3. Juni 2024, 10:21 +0100 schrieb Pim van der Heijden @.***>:
- I do need get_it for getting my AppState instance and other helper class instances outside of Widget contexts.
- Thanks, very clear.
- I'm not sure what clutter in my Widgets you mean. With provider I do:
var foo = context.watch
().foo; Whereas with watch_it I would do this for every value I have. final foo = watchPropertyValue((AppState a) => a.foo);
- Depends on the answer to 3. I would say
β Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
So the clutter we're talking about effectively is just the ChangeNotifierProvider
here?
var appState = AppState();
runApp(
ChangeNotifierProvider(
create: (context) {
return appState;
},
child: MyApp(),
),
)
Besides a different API, watch_it
is not focussed on making an app more cpu efficient? I mean, if it would be more performant than provider
than that would be a clear benefit to me.
If you have only one provider that's probably not a big deal. If you provide multiple objects it can get a bit crowded π Am 4. Juni 2024, 12:09 +0100 schrieb Pim van der Heijden @.***>:
So the clutter we're talking about effectively is just the ChangeNotifierProvider here? var appState = AppState();
runApp( ChangeNotifierProvider( create: (context) { return appState; }, child: MyApp(), ), ) β Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
all right then
Nope, I don't think that there is any performance benefits on either side. Watch_it offers some additional functions like pushScope, callOnce or onDispose which let's you do things in stateless widgets that would normally not be possible. But in general it's mostly a matter of taste. Am 4. Juni 2024, 12:12 +0100 schrieb Pim van der Heijden @.***>:
Besides a different API, watch_it is not focussed on making an app more cpu efficient? I mean, if it would be more performant than provider than that would be a clear benefit to me. β Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
Oooh that's nice. Thanks for the insightful conversation!
Hi!
I got very excited about
get_it
when I finally worked myself into so much trouble with globals and singletons that I decided to look for a more structured solution. I immediately understood intuitively what it was about and why it meant be added value for my code. Withwatch_it
, however, I'm clueless.Yes I'm looking for a simple state management solution, to remove clutter and organize my code. Yes I could use such a solution probably to optimise some code paths and some rendering. But, does
watch_it
do any of this? How so? How iswatch_it
different from the other tools out there?Thanks for clarifying, maybe it will create some nice content for the readme π Cheers π