You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.2 KiB
82 lines
2.2 KiB
import 'package:flutter/material.dart';
|
|
|
|
import 'asset.dart';
|
|
import 'bee_scaffold.dart';
|
|
|
|
class SearchBarDemo extends StatefulWidget {
|
|
_SearchBarDemoState createState() => _SearchBarDemoState();
|
|
}
|
|
|
|
class _SearchBarDemoState extends State<SearchBarDemo> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BeeScaffold(
|
|
title: 'SearchBarDemo',
|
|
actions: [
|
|
IconButton(
|
|
icon: Icon(Icons.search),
|
|
onPressed: () {
|
|
showSearch(context: context, delegate: SearchBarDelegate());
|
|
}
|
|
// showSearch(context:context,delegate: searchBarDelegate()),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class SearchBarDelegate extends SearchDelegate<String> {
|
|
@override
|
|
List<Widget> buildActions(BuildContext context) {
|
|
return [
|
|
IconButton(
|
|
icon: Icon(Icons.clear),
|
|
onPressed: () => query = "",
|
|
)
|
|
];
|
|
}
|
|
|
|
@override
|
|
Widget buildLeading(BuildContext context) {
|
|
return IconButton(
|
|
icon: AnimatedIcon(
|
|
icon: AnimatedIcons.menu_arrow, progress: transitionAnimation),
|
|
onPressed: () => close(context, null));
|
|
}
|
|
|
|
@override
|
|
Widget buildResults(BuildContext context) {
|
|
return Container(
|
|
width: 100.0,
|
|
height: 100.0,
|
|
child: Card(
|
|
color: Colors.redAccent,
|
|
child: Center(
|
|
child: Text(query),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget buildSuggestions(BuildContext context) {
|
|
final suggestionList = query.isEmpty
|
|
? recentSuggest
|
|
: searchList.where((input) => input.startsWith(query)).toList();
|
|
return ListView.builder(
|
|
itemCount: suggestionList.length,
|
|
itemBuilder: (context, index) => ListTile(
|
|
title: RichText(
|
|
text: TextSpan(
|
|
text: suggestionList[index].substring(0, query.length),
|
|
style: TextStyle(
|
|
color: Colors.black, fontWeight: FontWeight.bold),
|
|
children: [
|
|
TextSpan(
|
|
text: suggestionList[index].substring(query.length),
|
|
style: TextStyle(color: Colors.grey))
|
|
])),
|
|
));
|
|
}
|
|
}
|