繁体   English   中英

搜索用户类型功能抖动

[英]Search as user types functionality flutter

用户在搜索栏中键入内容并在用户键入时进行 API 调用并且他们永远不必单击搜索时调用的功能是什么?

我不想要预先输入,我希望特别能够在用户在搜索栏中键入时发送 http 请求,并将结果作为搜索栏下方的多个卡片返回。

flutter_typeahead 包类似,但我希望能够控制结果发生的情况。

好吧,你可以做这样的事情

double waitForInputInterval = 300 // ms
double lastKeyStroke = null;

void search(String searchedTerm) {
  final now = DateTime.now();


    // wait 300ms before sending api requests;
   if( lastKeyStroke != null && now.millisecond- lastKeyStroke <  waitForInputInterval ) {
      // send api request setState and other stuff
    }
   // for the first time
    else {
      lastKeyStroke = DateTime.now().millisecond;

     }
}


/// inside build

TextField(
onChange: search
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM