当没有角色颤动时,Textformfield on Changed不会被调用
我有1个功能,可以在按钮上添加textformfield,按下最多4个textformfield,如下图所示,当Textformfield中没有文本时,我想删除该TextFormField,因此我将该登录名放入Onchange中。
当我按按钮1S时间时,如果我从键盘上按键盘的删除按钮,则不会添加TextFormField,而不会键入任何字符。
这是我的代码。
TextFormField(
controller: bullet2Controller,
focusNode: focusNode2,
maxLines: null,
minLines: 1,
textCapitalization:TextCapitalization.sentences,
cursorColor: Colors.black,
showCursor: true,
autofocus: true,
textAlign: TextAlign.start,
inputFormatters: [LengthLimitingTextInputFormatter(140),],
onChanged: (value) {
setState(() {
if (value.isEmpty) {
isBullet2Visible = false;
if (isBullet1Visible) {
focusNode1.requestFocus();
} else if (isBullet3Visible) {
focusNode3.requestFocus();
} else if (isBullet4Visible) {
focusNode4.requestFocus();
} else {
FocusScope.of(context).unfocus();
}
if (_counter > 0) {
_counter--;
}
}
if (kDebugMode) {
print("${value.length.toString()} character(s)");
}
});
},
decoration: const InputDecoration(disabledBorder:
InputBorder.none,
border:
InputBorder.none,
filled: true,
fillColor: Colors.white,
),
keyboardType:
TextInputType
.multiline,
textInputAction:
TextInputAction.done,
),
是默认行为还是我需要采取任何额外的步骤才能使其正常工作。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是默认行为。
当您的值=''并按DELETE时,它仍然等于'',并且没有被调用。
为了实现目标,您应该使用RawKeyboardListener等听众
this is a default behaviour.
when your value = '' and you press delete it is still equal to '' and onChanged not getting called.
to achieve your goals you should use a listener like RawKeyboardListener
感谢Vladyslav Ulianytskyi的建议。
我已经使用
rawKeyboardListner
来完成此操作。这是示例代码。Thanks to Vladyslav Ulianytskyi suggestion.
I have done this with the use of
RawKEyboardListner
. Here is the sample code.您可以尝试下面的代码,希望它对您有用,
让我知道它是否适合您,或者让我知道是否有任何问题。
You can try it will below code hope it's work for you
let me know if it's work for you or let me know if there any question.