【发布时间】:2021-05-11 02:24:17
【问题描述】:
如何在颤动中禁用/删除textField 的控制侦听器,我正在使用 3 个textField 连接一个简单的数学.. (textField1 + textField2 = textField3) & ( textField1 - textField3 = textField2)... 我需要更改 textField3 的值并保持 textField2 的值不变?目前的情况是这样的
这是我的代码
@override
void initState() {
super.initState();
_focus.addListener(() {
if (_focus.hasFocus) {
_finalValue.clear();
}
});
_focuselocity.addListener(() {
if (_focuselocity.hasFocus) {
velocityEditingController.clear();
}
});
textEditingController.addListener(() => setState(() {}));
velocityEditingController.addListener(() => setState(() {
totalCalculated();
}));
_finalValue.addListener(() => setState(() {
totalCalculated();
}));
}
@override
void dispose() {
super.dispose();
velocityEditingController.removeListener(() {
totalCalculated();
});
textEditingController.removeListener(() {
totalCalculated();
});
_finalValue.removeListener(() {
totalCalculated();
});
}
String totalCalculated() {
airFlowText = textEditingController.text;
velocityText = velocityEditingController.text;
finalText = _finalValue.text;
if (airFlowText != '' && velocityText != '' && !_focus.hasFocus) {
sam = (int.parse(airFlowText) + int.parse(velocityText)).toString();
lastVelocityValue = velocityText;
_finalValue.value = _finalValue.value.copyWith(
text: sam.toString(),
);
}
if (airFlowText != '' && finalText != null && !_focuselocity.hasFocus) {
sam = (int.parse(airFlowText) - int.parse(finalText)).toString();
velocityEditingController.value =
velocityEditingController.value.copyWith(
text: sam.toString(),
);
}
return sam;
}
【问题讨论】:
标签: android flutter listener textfield