inherited method Null safety

Widget inherited(
  1. {Key? key,
  2. required Widget builder(
    1. BuildContext
  3. required FutureOr<T> stateOverride(
    1. bool connectWithGlobal = true,
    2. SideEffects? sideEffects,
    3. String? debugPrintWhenNotifiedPreMessage,
    4. String toDebugString(
      1. T?

    Provide the injected model using an InheritedWidget that wraps its state.

    By default the InheritedWidget holds the state of the injected model, but this can be overridden using the stateOverride parameter.

    Child widgets can obtain the wrapped state using .of(context) or .call(context) methods.

    • myModel.of(context) looks up in the widget tree to find the state of myModel and register the BuildContext to rebuild when myModel is notified.

    • or myModel(context) looks up in the widget tree to find the injected model myModel without registering the BuildContext.


    final counter1 = RM.inject<int>(()=> 0);
    final counter2 = RM.inject<int>(()=> 0);
    class MyApp extends StatelessWidget{
    Widget build(context){
      builder: (context):{
        return counter2.inherited(
          builder: (context){
            //Getting the counters state using `of` will
            //resister this BuildContext
            final int counter1State = counter1.of(context);
            //Although both counters are of the same type we get
            //the right state
            final int counter2State = counter2.of(context);
            //Getting the counters using the `call` method will
            //not register this BuildContext
             final Injected<int> counter1 = counter1(context);
             final Injected<int> counter2 = counter2(context);
    • Required parameters:
      • builder: Callback to be rendered. It exposed the BuildContext.
    • Optional parameters:
      • stateOverride: CallBack to override the exposed state.
      • connectWithGlobal: If state is overridden, whether to mutate the global
      • debugPrintWhenNotifiedPreMessage: if not null, print an informative message when this model is notified in the debug mode.The entered message will prĂ©-append the debug message. Useful if the type of the injected model is primitive to distinguish


    Widget inherited({
      Key? key,
      required Widget Function(BuildContext) builder,
      required FutureOr<T> Function()? stateOverride,
      bool connectWithGlobal = true,
      SideEffects? sideEffects,
      String? debugPrintWhenNotifiedPreMessage,
      String Function(T?)? toDebugString,
      // bool keepAlive = false,