flutter - 如何在 Flutter 中使用 SearchDelegate 打开一个新页面
问题描述
我目前正在我的颤振应用程序中开发搜索功能。搜索功能起作用并在 ListTile 中显示结果。但我想导航到 ListTile 中显示的每个结果的特定页面。如果我在 ListTile 中使用 onTap 函数,如何将结果与其特定页面相匹配?
这是我的字符串列表:
final testList = [
'test 1',
'test 2',
'test 3',
'test 4',
];
我使用 SearchDelegate 来搜索结果:
@override
List<Widget> buildActions(BuildContext context) {
return [
IconButton(
onPressed: () {
query = '';
},
icon: Icon(Icons.clear)),
];
}
@override
Widget buildLeading(BuildContext context) {
return IconButton(
onPressed: () {
close(context, null);
},
icon: AnimatedIcon(
icon: AnimatedIcons.menu_arrow, progress: transitionAnimation));
}
@override
Widget buildResults(BuildContext context) {
return Container(
height: 100,
width: 100,
child: Card(
color: Colors.red,
child: Center(child: Text(query),),
),
);
}
@override
Widget buildSuggestions(BuildContext context) {
final suggestionList = query.isEmpty
? testList
: testList.where((p) => p.startsWith(query)).toList();
return ListView.builder(
itemBuilder: (context, index) => ListTile(
tileColor: backGround,
onTap: () {
showResults(context);
},),
itemCount: suggestionList.length,
);
}
}
解决方案
推荐阅读
- javascript - 在 mongoDB 和 Angular 中实现 socket.io 会引发错误 Cannot GET /socket.io/
- c# - 浏览器意外刷新时的 Blazor WebAssembly 生命周期方法
- spring-boot - 是否可以告诉 spring cloud sleuth 不记录密码等值?
- reactjs - PDFTron 中的滚动页面
- google-sheets - 将 2 个 REGEXREPLACE 公式合二为一
- matlab - 为反相流创建方程矩阵
- javascript - 如何通过比较 JavaScript 中的两个字符串从字符串中获取一个值?
- python - 为什么 subprocess 不会仅以 Python 2.7 终止?
- android - Google Play 控制台 - Android Bundle 权限问题
- mongodb - Javers 异步提交到 Mongo DB