Flutter实现搜索的三种方式

示例 1 :使用搜索表单创建全屏模式

我们要构建的小程序在右侧有一个应用程序栏和一个搜索按钮。当您按下此按钮时,将出现全屏模式对话框。它不是突然弹出的,而是带有淡入淡出动画和幻灯片动画(从上到下)。在循环搜索字段旁边,有一个取消按钮,可用于关闭模式。在搜索字段下方,我们将显示一些搜索历史记录(您可以添加其他内容,如建议、类别等)。

[En]

The applet we are going to build has an application bar and a search button on the right. When you press this button, a full-screen mode dialog box appears. It does not pop up suddenly, but with fade in and out animation and slide animation (from top to bottom). Next to the circular search field, there is a * cancel * button that can be used to turn off mode. Below the search field, we will display some search history (you can add other content, such as suggestions, categories, etc.).

我们通过定义一个扩展 ModalRoute 类的名为 FullScreenSearchModal的类来创建完整模式。

main.dart中的完整源代码及说明:

示例 2:AppBar 内的搜索字段(最常见于娱乐应用程序)

通常,许多娱乐应用程序(包括 Facebook、Youtube、Spotify 等大型应用程序)默认不显示搜索字段,而是显示搜索图标按钮。按下此按钮时,将显示搜索字段。

我们要制作的演示应用程序包含 2 个屏幕(页面): HomePageSearchPage。用户可以通过点击搜索图标按钮从主页移动到搜索页面。搜索字段将通过使用SearchPage 的 AppBar的 title参数来实现。

让我们看看它是如何工作的:

[En]

Let’s see how it works:

./lib/main.dart中的完整源代码及说明:

示例 3:搜索字段和 SliverAppBar

广告搜索是许多电子商务应用程序最重要的功能之一,因此它们通常以最容易识别的方式显示搜索字段,并且从一开始就占用大量空间(亚马逊、Shopee 等)。

您已经研究了在 Flutter 中实现全屏搜索框的端到端示例。这种搜索方式如今非常流行,您可以在许多大型应用程序和移动网站中注意到它。通过查看以下文章,继续学习并获得更多移动开发经验:

~~~~

Original: https://blog.51cto.com/jianguo/5573452
Author: 大前端之旅
Title: Flutter实现搜索的三种方式

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/508519/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球