简体   繁体   English

如何使用 rest api flutter 执行搜索功能

[英]how to do search functionality using rest api flutter

I want to search the products data and show the searched data in the below as list up to 15 items if 16 item is entered than automatically the first item will be deleted.can any one help me how to do this in flutter我想搜索产品数据并在下面将搜索到的数据显示为最多 15 个项目,如果输入 16 个项目而不是自动删除第一个项目。谁能帮我在 flutter 中执行此操作

As you written正如你所写

when we search the item in the search box it will store in the local db当我们在搜索框中搜索项目时,它将存储在本地数据库中

So you can get only first 15 items using the same query.因此,您只能使用相同的查询获得前 15 个项目。 By that using pagination you can show remaining items.通过使用分页,您可以显示剩余项目。 I can't get the use case of removing the top item if there are more than n items in list.如果列表中有超过n项目,我无法获得删除顶部项目的用例。

But if you want, you can do this by two ways.但如果你愿意,你可以通过两种方式做到这一点。

First , putting items one by one in the list.首先,将项目一个一个地放入列表中。 Inside this loop if item count is more than 15 after inserting a new item, just remove the first item如果在插入新项目后项目计数超过 15,则在此循环内,只需删除第一个项目

list.removeAt(0); list.removeAt(0);

Second , add the items in array, check for length.其次,在数组中添加项目,检查长度。 If length is greater than 15 get the remaining number & run如果长度大于 15,则获取剩余数字并运行

list.removeRange(0, ); list.removeRange(0, );

This will remove the items from top这将从顶部删除项目

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

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