useListenableSelector<R> function Null safety

R useListenableSelector<R>(
  1. Listenable listenable,
  2. R selector(
      )
    )

    Rebuild only when there is a change in the selector result.

    The following example showcases If no text is entered, you will not be able to press the button.

    class Example extends HookWidget {
      @override
      Widget build(BuildContext context) {
       final listenable = useTextEditingController();
       final bool textIsEmpty =
            useListenableSelector(listenable, () => listenable.text.isEmpty);
       return Column(
          children: [
            TextField(controller: listenable),
            ElevatedButton(
                // If no text is entered, the button cannot be pressed
                onPressed: textIsEmpty ? null : () => print("Button can be pressed!"),
                child: Text("Button")),
          ],
        );
      }
    }
    

    Implementation

    R useListenableSelector<R>(
      Listenable listenable,
      R Function() selector,
    ) {
      return use(_ListenableSelectorHook(listenable, selector));
    }