简体   繁体   English

如何在包含大量产品的 Flutter 电子商务应用程序中实现搜索栏?

[英]How to implement a search bar in flutter E-commerce app with tons of products?

I've been developing an E-commerce app.我一直在开发电子商务应用程序。 It has a lot of products as of now and more are being added every day .到目前为止,它有很多产品,而且每天都在添加更多产品。 I'm thinking of making a list of thousands of products (all of them) and do a linear search .我正在考虑列出数千种产品(所有产品)并进行线性搜索 Is there a better way to implement it.有没有更好的方法来实现它。 Suggest me some best practices.建议我一些最佳实践。 Thanks.谢谢。

here's a package you can use Flutter Search Bar , personally I just use a second List and this simple function:这是一个可以使用Flutter Search Bar的包,我个人只使用第二个 List 和这个简单的功能:

final List<String> filteredNames;
final List<String> names = [
  //your data or database
];

onChanged: (input) {
  input = input.toLowerCase(); //for no case-sensitive search
    setState(() {
      filteredNames = names.where((name) {
        var exName = name.toLowerCase();
        return exName.contains(input);
      }).toList();
   });
},

It's easy to implement but the downside is bad performance for very large lists (a few thousands should be working fine I think, try it out).它很容易实现,但缺点是非常大的列表性能不佳(我认为几千应该可以正常工作,请尝试一下)。

For handling search in really large lists check out Stack Overflow-How to handle searching large lists in Flutter?要在非常大的列表中处理搜索,请查看Stack Overflow-How to handle search large list in Flutter?

暂无
暂无

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

相关问题 如何在使用 Firebase 的电子商务应用程序中的预计交货时间结束时通知店主 - How to notify a store owner when the estimated delivery time is over in an e-commerce app using firebase 带有Android电子商务应用程序的WooCommerce REST API - WooCommerce REST API with Android e-commerce app 添加商品数量(电子商务/商店应用程序) - Add the quantity of items (e-commerce/shop app) 我应该制作原生还是混合电子商务应用程序? - Should i make native or hybrid e-commerce app? 如何使用电子商务应用程序中用户提供的详细信息从应用程序发送确认订单的官方确认邮件。 - How to send an official confirmation mail of confirming order from an app using the details provided by user in a e-commerce app. 如何使用WooCommerce维护我的WordPress电子商务网站上的会话以及如何使用WooCommerce rest API维护我的android应用上的会话? - How to maintain session on my WordPress e-commerce website using WooCommerce and my android app using WooCommerce rest API? 我们应该为电子商务android应用程序使用后端代码还是客户端代码 - Should we use backend code or Client side code for e-commerce android app 像亚马逊这样的电子商务应用程序如何知道用户点击了哪个商品 - How do e-commerce apps like Amazon get to know which item user clicked 电子商务安卓应用 - E commerce android app 跟踪随GCM发送的推送通知是否导致电子商务销售 - Track if push notification sent with GCM resulted into e-commerce sale
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM