Coming from package:provider I'm testing lite_ref and context_plus. All get the job done.
context_plus has some interesting (syntactic) features, I'd love to see in lite_ref, too.
bind
class ControlPageController extends BeaconController {
static final ref = Ref<ControlPageController>();
late final list = B.list<String>(['a', 'b', 'c']);
}
@override
Widget build(BuildContext context) {
// bind ControlPageController to context, accessible via ControlPageController.ref for all children
ControlPageController.ref.bind(context, () => ControlPageController());
// directly available, without Builder()
final controller = ControlPageController.ref.of(context);
print(controller); // directly accessible
return SizedBox();
}
With lite_ref, passing anything down to the child widgets requires wrapping with LiteRefScope with overrides and a Builder to access it directly
@override
Widget build(BuildContext context) {
return LiteRefScope(
overrides: {
// provides ControlPageController to all child widgets
ControlPageController.ref..overrideWith((ctx) => ControlPageController()),
},
child: Builder(
builder: (context) {
// requires new context to access the controller
final controller = ControlPageController.ref.of(context);
print(controller);
return SizedBox();
}
),
);
}
The syntax it is not a dealbreaker. But it is quite verbose and adds two levels of nesting.
That I have to define overrides feels off. It might be the only time I provide a value to child widgets, not overriding anything.
Would this bind API be possible for lite_ref, too?
Coming from
package:providerI'm testinglite_refandcontext_plus. All get the job done.context_plushas some interesting (syntactic) features, I'd love to see inlite_ref, too.bind
With
lite_ref, passing anything down to the child widgets requires wrapping withLiteRefScopewithoverridesand a Builder to access it directlyThe syntax it is not a dealbreaker. But it is quite verbose and adds two levels of nesting.
That I have to define
overridesfeels off. It might be the only time I provide a value to child widgets, not overriding anything.Would this
bindAPI be possible forlite_ref, too?