flutter - 如何在此应用的 Appbar 中添加搜索选项?
问题描述
我想在这个应用程序中添加搜索选项。在 Appbar 中添加搜索栏,然后在 Listview 中创建过滤器/搜索。
这意味着,在我的 Appbar 中,如果它与列表中的任何项目匹配,我将在搜索栏中输入,它会显示该项目。列表的数据来自 CSV 文档。所以我觉得它很复杂。
我该怎么做?我已在帖子中部分附加了我的代码。
提前致谢。
解决方案
title
您可以像在 appBar 中一样添加搜索栏。
title: Padding(
padding: EdgeInsets.only(top: 8),
child: Container(
height: 40,
margin: EdgeInsets.symmetric(horizontal: 10, vertical: 15),
decoration: BoxDecoration(
color: Color.fromARGB(70, 255, 255, 255),
borderRadius: BorderRadius.all(Radius.circular(15.0))),
child: TextFormField(
textInputAction: TextInputAction.search,
onFieldSubmitted: (value) async {},
style: TextStyle(color: Colors.white, fontSize: 15),
cursorColor: Colors.white,
textAlign: TextAlign.left,
controller: _textFieldController,
decoration: InputDecoration(
suffixIcon: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween, // added line
mainAxisSize: MainAxisSize.min, // added line
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 10, right: 10),
child: InkWell(
onTap: () async {},
child: Icon(Icons.search,
color: Colors.white))),
],
),
isDense: true,
border: InputBorder.none,
hintText: "Search",
contentPadding:
EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 10.0),
hintStyle:
TextStyle(color: Colors.white, fontSize: 15)),
))),
推荐阅读
- android - RecyclerView:没有附加适配器;在适配器中创建充气机时跳过布局应用程序关闭
- python - Python 脚本未能正确编码特殊的 Unicode 字符
- svelte - 你如何处理 svelte 中的函数参数?
- python - 如何在不使用 splat 运算符的情况下解压缩具有不同数量元素的元组?
- mysql - 如果某些列是可选的,那么用覆盖索引查询一堆列的最佳方法是什么?
- r - 我有两个长度不等的数据框,我想与特定的 NA 位置结合
- bash - 使用 Shell 脚本控制另一个程序
- java - java处理中与二维数组的交互
- angular - 角度过滤器在多个数组中查找字符串
- reactjs - 价值未发送