useDependentProp<T extends StatefulProp> method

T useDependentProp<T extends StatefulProp>(
  1. String id, {
  2. required T create(
    1. BuildContext c,
    2. W w
    ),
})

Similar to useProp, but allows a prop to bind to external dependencies, either from the Widget or an InheritedWidget. The create method is re-run when dependencies change and the props can update themselves with the latest values.

Implementation

T useDependentProp<T extends StatefulProp<dynamic>>(String id, {required T Function(BuildContext c, W w) create}) {
  // Because of how dart handles Generic, we can's cast Function(MyWidget) to Function(Widget),
  // but we can make it happen with a fancy little closure :) Declare the method signature that we need, then, internally do the cast, which will work correctly.
  T Function(BuildContext, Widget) _c = (c, w) => create.call(c, w as W);
  return _controller.useDependentPropWithId(id, _c, id);
}