As soon as a TextField
gets focused, an object which stores if it's enabled changes so that the TextField
gets disabled immediately. This also happens when another TextField
above gets focused.
The TextField
is placed inside a StatefulWidget and a Category
object contains another object called Goal
which contains a bool
variable if it's enabled or disabled. This variable is also used to enable or disable the TextField
.
TextField(
controller: _goalAmountController,
enabled: widget.category.goal.enabled,
decoration: InputDecoration(
labelText: "Goal Amount",
border: OutlineInputBorder(),
),
onChanged: (value) {
try {
widget.category.goal.amount = double.parse(value);
} on Exception {
//TODO display error message
print("Invalid Goal-Amount");
}
},
),
There's also a switch
below the TextField
to enable or disable the Goal
by setting it's enabled
variable.
SwitchListTile(
value: widget.category.goal.enabled,
title: Text("Enable Goal"),
onChanged: (value) {
setState(
() {
widget.category.goal.enabled = value;
},
);
},
),
I found out that it seems as if the click on a TextField
would replace the Goal
object with a new one which has false
as the default value for enabled
.