The Problem
The isEmpty check is returning true for a non-empty String field. My guess is – TextEditingController’s String metadata is not updating with string update from an async load.
- I’m not sure if I’m missing something obvious or if this is a Dart/Flutter bug.
- Is there an idiomatic way to accomplish this check?
Here’s my code
var textController = TextEditingController();
@override
void initState() {
super.initState();
init();
}
void init() async {
final foo = await FooProvider.instance.getFoo(widget.uuid);
textController.text = foo.title;
}
The actual usage of the textController,
GestureDetector(
onTap: textController.text.isEmpty
? () {
debugPrint('Empty - ${textController.text}');
}
: () {
// rest of the code
Output
(With actual field value "abc")

>Solution :
An alternative solution is to do the check inside a single implementation of onTap instead of two different ones, like this
GestureDetector(
onTap: () {
if (textController.text.isEmpty) {
debugPrint('Empty - ${textController.text}');
} else {
// rest of the code
}
}