[英]Flutter TextFormField call value change method after finish text input
In my screen there are search features as per logic that's working fine but issue is I want to run my search function after stope typing??在我的屏幕中,有符合逻辑的搜索功能运行良好,但问题是我想在停止输入后运行我的搜索功能? So in the
TextFormField
there are onChanged
method, how can we achieve it?那么
TextFormField
有onChanged
方法,如何实现呢? I tried lots of ways like comparing DateTime
but not able to achieved it.我尝试了很多方法,比如比较
DateTime
但无法实现。
~ PS : onEditingComplete
method works perfect in my case but issues is, To call this method I have to click on return button, without click on return button is it possible? ~ PS:
onEditingComplete
方法在我的情况下很完美,但问题是,要调用这个方法,我必须点击返回按钮,而不点击返回按钮是否可能?
I would suggest to create a debouncer, something like this.我建议创建一个 debouncer,像这样。
class Debouncer {
final int milliseconds;
VoidCallback action;
Timer _timer;
Debouncer({this.milliseconds});
run(VoidCallback action) {
if (null != _timer) {
_timer.cancel();
}
_timer = Timer(Duration(milliseconds: milliseconds), action);
}
}
Then initiate the object with your desired time of "after stop typing".然后以您想要的“停止打字后”的时间启动对象。
final _debouncer = Debouncer(milliseconds: 1000);
And use it in your onChanged method.并在您的 onChanged 方法中使用它。
onChanged: (string) {
_debouncer.run(() {
//Perform your search
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.