'why can't I see updates to the value of useTextEditingController?
I would expect the effect to log the current value of the text whenever it changes, but it only runs for the initial value. Why?
class RecordForm extends HookWidget {
final Record? record;
const RecordForm({
Key? key,
this.record,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final initialTitle = record != null ? record!.title : "";
final _title = useTextEditingController
.fromValue(TextEditingValue(text: initialTitle));
useEffect((){
log.wtf(_title.value.text);
}, [_title.value]);
return // ...
TextFormField(
controller: _title,
// ...
),
// ...
;
}
}
Solution 1:[1]
Doing it that way initializes the TextEditingController once. I think if you want to listen to real-time changes you have to add a listener to it.
TextEditingController controller = useTextEditingController();
controller.addListener(() {
print(controller.text);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Joe Muller |
