3 Star 51 Fork 35

语辰软件/ShirneApp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
search.dart 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
shirne 提交于 1年前 . upgrade pkgs
import 'package:flutter/material.dart';
class SearchPage extends StatefulWidget {
const SearchPage({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => _SearchPageState();
}
class _SearchPageState extends State<SearchPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('搜索效果'),
actions: <Widget>[
IconButton(
onPressed: () {
showSearch(context: context, delegate: SearchBarDelegate());
},
icon: const Icon(Icons.search),
),
],
),
body: const Center(child: Text('test search')),
);
}
}
class SearchBarDelegate extends SearchDelegate<String> {
@override
List<Widget> buildActions(BuildContext context) {
return [
IconButton(
icon: const 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, '');
} else {
query = "";
showSuggestions(context);
}
},
);
}
@override
Widget buildResults(BuildContext context) {
return const Center(
child: Text('buildResults'),
);
}
@override
Widget buildSuggestions(BuildContext context) {
return const Center(
child: Text('buildSuggestions'),
);
}
@override
ThemeData appBarTheme(BuildContext context) {
final ThemeData theme = Theme.of(context);
return theme.copyWith(
primaryColor: Colors.white,
primaryIconTheme: theme.primaryIconTheme.copyWith(color: Colors.grey),
primaryTextTheme: theme.textTheme,
);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Dart
1
https://gitee.com/shirnecn/ShirneApp.git
git@gitee.com:shirnecn/ShirneApp.git
shirnecn
ShirneApp
ShirneApp
master

搜索帮助