rodydavis / signals.dart

Reactive programming made simple for Dart and Flutter
http://dartsignals.dev
Apache License 2.0
465 stars 52 forks source link

[Feature request] Watch() widget with finer grain control like ValueListenableBuilder #33

Closed scalz closed 11 months ago

scalz commented 11 months ago

Hello,

Thank you for sharing your work. It shares some concepts with Mobx and Solidart. I like to use Mobx, or vanilla ValueNotifier etc but your implementation is interesting too :)

What do you think about adding finer grain control to Watch() widget, like ValueListenableBuilder can do ? They added this option recently in Mobx Observer() widget.

Watch((context, Widget? child) {
    return MyWidget('$counter', child: child!);
  },
  child: DoNotRebuildWidget(...),
)

or like these but currently, Watch builder is required

Watch(
  builderWithChild: (context, child) {
    return MyWidget('$counter', child: child!);
  },
  child: DoNotRebuildWidget(...),
)

Watch.withChild(
  builderWithChild: (context, child) {
    return MyWidget('$counter', child: child!);
  },
  child: DoNotRebuildWidget(...),
)
rydmike commented 11 months ago

If you split your Widgets and logic into smaller parts this can perhaps be worked around. I can appreciate this for convenience and it is very useful and handy with animations that also have a child does not change during the animation.

However, I also like that currently I can just use IDE feature and the standard "Wrap with Builder" and change it to "Watch" with its current signature.

I like the proposal, but I would prefer an addition that does not to break Watch current signature, also for backwards API compatibility. Consider adding another watcher for this.

rodydavis commented 11 months ago

You can make any signal into a ValueListenable and use with ValueListenenableBuilder if you prefer: https://rodydavis.github.io/signals.dart/reference/value-listenable/

But the intention of the watch widget is to be as minimal as possible

scalz commented 11 months ago

Good point :) And I can make a custom watch widget if I really need it, that's fine too. Thx

rodydavis commented 11 months ago

I'm going to close this for now, but going to convert this to a discussion!