使用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. 03-【request对象获取请求的数据 & request对象存取值】

    request概述(封装了客户端所有的请求数据) request是Servlet.service()方法的一个参数,类型为javax.servlet.http.HttpServletRequest.在 ...

  2. 笔记 前端的$dom操作

    jqueryDOM操作  1.  页面加载  函数 $( function(){ 具体内容 } );        表示页面加载函数   2  dom 类操作 text() - 设置或返回所选元素的文 ...

  3. 适配器 1、ArrayAdapter 2.SimpleAdapter

    1.ArrayAdapter(数组适配器):用于绑定格式单一的数据.数据源:可以是集合或数组 public class MainActivity extends AppCompatActivity { ...

  4. bootstrap和JS实现下拉菜单

    // bootstrap下拉菜单 <div class="btn-group"> <button id="button_text" type= ...

  5. 5.Dropout

    import numpy as np from keras.datasets import mnist from keras.utils import np_utils from keras.mode ...

  6. for(auto count:counts)

    c++中for(auto count : counts) 这是C++11中的语法,即:Range-based for loop.其中counts应满足:begin(counts), end(count ...

  7. 配置LANMP环境(6)-- 安装APACHE与PHP配置

    一.安装 Apache 2.4 安装:默认安装2.4版本 yum install httpd 修改配置 vim /etc/httpd/conf/httpd.conf 42行80端口改为 8080查看行 ...

  8. TCP的ACK原理和延迟确认机制

    某天晚上睡觉前突然想到 tcp的ACK确认是单独发的还是和报文一起发的,下面看一下别人的解答 一.ACK定义TCP协议中,接收方成功接收到数据后,会回复一个ACK数据包,表示已经确认接收到ACK确认号 ...

  9. Hadoop-No.8之时间戳

    要获得良好的HBase的模式设计,要正确的理解和使用时间错.在HBase中,时间戳的作用如下所述. 时间戳决定了在put请求修改记录时那些记录更新 时间戳决定了一条记录的多个版本在返回时的排序 时间戳 ...

  10. [Spring Boot] Aspect Intro

    Aspect-Oriented Programming (AOP) complements Object-Oriented Programming (OOP) by providing another ...