使用searchDelegate可以很轻松实现以下页面

import 'package:flutter/material.dart';

typedef SearchItemCall = void Function(String item);

class SearchBarDelegate extends SearchDelegate<String> {

  @override
List<Widget> buildActions(BuildContext context) {
//右侧显示内容 这里放清除按钮
return [
IconButton(
icon: Icon(Icons.clear),
onPressed: () {
query = "";
showSuggestions(context);
},
),
];
} @override
Widget buildLeading(BuildContext context) {
//左侧显示内容 这里放了返回按钮
return IconButton(
icon: AnimatedIcon(
icon: AnimatedIcons.menu_arrow, progress: transitionAnimation),
onPressed: () {
if (query.isEmpty) {
close(context, null);
} else {
query = "";
showSuggestions(context);
}
},
);
} @override
Widget buildResults(BuildContext context) {
//点击了搜索显示的页面
return Center(
child: Text('12312321'),
);
} @override
Widget buildSuggestions(BuildContext context) {
//点击了搜索窗显示的页面
return SearchContentView();
} @override
ThemeData appBarTheme(BuildContext context) {
return super.appBarTheme(context);
}
} class SearchContentView extends StatefulWidget {
@override
_SearchContentViewState createState() => _SearchContentViewState();
} class _SearchContentViewState extends State<SearchContentView> {
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Text(
'大家都在搜',
style: TextStyle(fontSize: 16),
),
),
SearchItemView(),
Container(
margin: EdgeInsets.only(top: 20),
child: Text(
'历史记录',
style: TextStyle(fontSize: 16),
),
),
SearchItemView()
],
),
);
}
} class SearchItemView extends StatefulWidget {
@override
_SearchItemViewState createState() => _SearchItemViewState();
} class _SearchItemViewState extends State<SearchItemView> {
List<String> items = [
'面试',
'Studio3',
'动画dfsfds',
'自定义View',
'性能优化',
'gradle',
'Camera',
'代码混淆 安全',
'逆向加固'
];
@override
Widget build(BuildContext context) {
return Container(
child: Wrap(
spacing: 10,
// runSpacing: 0,
children: items.map((item) {
return SearchItem(title: item);
}).toList(),
),
);
}
} class SearchItem extends StatefulWidget {
@required
final String title;
const SearchItem({Key key, this.title}) : super(key: key);
@override
_SearchItemState createState() => _SearchItemState();
} class _SearchItemState extends State<SearchItem> {
@override
Widget build(BuildContext context) {
return Container(
child: InkWell(
child: Chip(
label: Text(widget.title),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)
),
),
onTap: () {
print(widget.title);
},
),
color: Colors.white,
);
}
}

使用

  @override
Widget build(BuildContext context) {
return Scaffold(
// appBar: AppBar(),
body: Center(
child: InkWell(
child: Icon(Icons.search),
onTap: (){
showSearch(context: context,delegate: SearchBarDelegate());
},
)
),
);
}

flutter searchDelegate搜索页的更多相关文章

  1. iOS-PYSearch 完美搜索页

    APP搜索页基本上是少不了的,热门搜索.搜索记录等:这里推荐一个大牛ko1o写的:PYSearch,他还有一个不错的图片浏览开源:PYPhotoBrowser:这个也不错,感兴趣的可以了解下:下面说下 ...

  2. 织梦搜索页使用arclist标签

    织梦默认不能在搜索页使用arclist标签,我们对代码做一些小改动即可 打开include/arc.searchview.class.php 一.查找代码: require_once(DEDEINC. ...

  3. IIS下实现帝国CMS搜索页伪静态

    前面ytkah讲了apache下帝国CMS搜索页伪静态实现方法,网友说服务器是用IIS,那么IIS下如何实现帝国CMS搜索页伪静态呢?首先得先有URL重写插件,下载地址:http://www.iis. ...

  4. 织梦dedecms搜索页加上序列号autoindex

    在我们做织梦搜索页模板的时候经常会使用到autoindex标签.那么怎么才能实现搜索页可以使用呢?下面给大家分享下解决方法: 打开文件:include/arc.searchview.class.php ...

  5. DT6.0下搜索页解决canonical获取乱码问题

    最近研究dt6.0,官方内核默认是把搜索页屏蔽的,但是做seo的人都知道,搜索页聚合是争取排名的好地方,所以我就二次开发搜索页,具体可以查看前几期分享的,今天说说关于搜索的canonical的url乱 ...

  6. destoon6.0搜索页熊掌号页面改造技巧【原创】

    大家都知道,DT官方是封禁搜索页的,是不让百度蜘蛛抓取的,但是搜索页又是大型网站优化的重点,今天来说说关于DT6.0搜索页熊掌号的改造方法,如果您要改造内容页面可以查看我前几期的分享! 首先要开启百度 ...

  7. dede搜索页做法

    触发搜索页代码 <p class="fl"> <span>热门搜索:</span> {dede:hotwords num=8 subday=36 ...

  8. dedecms织梦搜索页错乱的解决方法

    在使用DEDE程序所架设的网站时,使用搜索结果页展示的问题上,由于font样式飘红问题,导致页面错乱,今天来解决这个问题. 织梦程序的搜索结果原理很简单,利用font加入颜色样式赋予搜索结果,所以显示 ...

  9. Flutter: SearchDelegate 委托showSearch定义搜索页面的内容

    API class _MyHomeState extends State<MyHome> { List<String> _list = List.generate(100, ( ...

随机推荐

  1. Redis的keyspace notification(键空间通知)

    文章来源https://www.cnblogs.com/tinywan/p/5903988.html 一.需求分析: 设置了生存时间的Key,在过期时能不能有所提示? 如果能对过期Key有个监听,如何 ...

  2. 原创:(一)TCP/IP学习笔记之概述

    端到端论点和命运共享其实不应该在底层,差错控制应该在应用程序附近来实现.这是因为考虑了连接,而不是传输的准确,因为差错可以根据某些算法(通信中的滤波等)来恢复,不过在大面积网络出现问题的时候有必要进行 ...

  3. ngnix 配置说明

    #定义Nginx运行的用户和用户组 user www www; # #nginx进程数,建议设置为等于CPU总核心数. worker_processes ; # #全局错误日志定义类型,[ debug ...

  4. 分布式之Zookeeper一(分布式锁与Zookeeper集群)

    说到分布式开发,不得不说的就是zookeeper了:zookeeper官网说到Apache ZooKeeper致力于开发和维护可实现高度可靠的分布式协调的开源服务器.那么zk作为一个协调者的存在,是分 ...

  5. LeetCode 01 两数之和

    链接:https://leetcode-cn.com/problems/two-sum 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们 ...

  6. 洛谷P3690 Link Cut Tree (动态树)

    干脆整个LCT模板吧. 缺个链上修改和子树操作,链上修改的话join(u,v)然后把v splay到树根再打个标记就好. 至于子树操作...以后有空的话再学(咕咕咕警告) #include<bi ...

  7. Vue双向绑定的实现原理系列(四):补充指令解析器compile

    补充指令解析器compile github源码 补充下HTML节点类型的知识: 元素节点 Node.ELEMENT_NODE(1) 属性节点 Node.ATTRIBUTE_NODE(2) 文本节点 N ...

  8. thinkjs 安装笔记

    1.首先安装thinkjsnpm install -g thinkjs(-g是指全局安装)检查是否安装成功:thinkjs -v 2.创建项目进入项目目录,初始化项目:thinkjs new proj ...

  9. Python-multiprocessing-Process模块

    获取当前执行该文件的进程ID import os # 获取当前执行该文件的进程ID print("Process (%s) start..." % os.getpid()) mul ...

  10. (转)rotatelogs - Piped logging program to rotate Apache logs

    原文:http://publib.boulder.ibm.com/httpserv/manual60/programs/rotatelogs.html rotatelogs is a simple p ...