useTextController function

UseTextController useTextController({
  1. String initialValue = "",
  2. int throttle = 0,
})

Implementation

UseTextController useTextController({
  String initialValue = "",
  int throttle = 0,
}) {
  final text = useState<String>(initialValue);
  final throttleFunction = useMemoized(() => DelayThrottle(throttle), []);

  final controller = useMemoized(() {
    final controller = TextEditingController();
    controller.text = initialValue;
    controller.addListener(() {
      if (throttle > 0) {
        throttleFunction <<
            () {
              text.value = controller.text;
            };
      } else {
        text.value = controller.text;
      }
    });
    return controller;
  }, []);

  return UseTextController(controller: controller, text: text.value);
}