provider icon indicating copy to clipboard operation
provider copied to clipboard

`context.select` in `ProxyProvider0.update` not allowed?

Open taosimple opened this issue 2 months ago • 1 comments

Discussed in https://github.com/rrousselGit/provider/discussions/873

Originally posted by taosimple April 19, 2024

ProxyProvider0<TransformedCounter>(
          update: (context, value) {
            final value = context.select<Counter, int>((counter) => counter.value);
            return TransformedCounter(value * 2);
          },
        ),

ProxyProvider0<TransformedCounter>(
          update: (context, value) {
            final counter = context.watch<Counter>();
            return TransformedCounter(counter.value * 2);
          },
        ),

Above codes use context.select will throw a exception: Tried to use context.select outside of the build method of a widget., but use context.watch is fine, why context.select is not allowed, it more efficient than context.watch.

taosimple avatar Apr 19 '24 02:04 taosimple

Technical limitation. We could possibly support it, but that's not a thing yet.

rrousselGit avatar Apr 19 '24 06:04 rrousselGit