useFormattedTextController top-level constant
_FormattedTextControllerHookCreator
const useFormattedTextController
Creates a FormattedTextEditingController, either via an initial text or an initial TextEditingValue.
To use a FormattedTextEditingController with an optional initial text, use
final controller = useFormattedTextController(text: 'initial text');
To use a FormattedTextEditingController with an optional initial value, use
final controller = useFormattedTextController
.fromValue(TextEditingValue.empty);
Changing the text or initial value after the widget has been built has no
effect whatsoever. To update the value in a callback, for instance after a
button was pressed, use the FormattedTextEditingController.text or
FormattedTextEditingController.value setters. To have the FormattedTextEditingController
reflect changing values, you can use useEffect
. This example will update
the FormattedTextEditingController.text whenever a provided ValueListenable
changes:
final controller = useFormattedTextController();
final update = useValueListenable(myTextControllerUpdates);
useEffect(() {
controller.text = update;
}, [update]);
See also:
- FormattedTextEditingController, which this hook creates.
Implementation
const useFormattedTextController = _FormattedTextControllerHookCreator();