57 lines
1.3 KiB
Dart
57 lines
1.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class CharacterSearchDelegate extends SearchDelegate<String> {
|
|
final List<String> suggestions;
|
|
|
|
CharacterSearchDelegate(this.suggestions);
|
|
|
|
@override
|
|
List<Widget>? buildActions(BuildContext context) {
|
|
return [
|
|
IconButton(
|
|
icon: Icon(Icons.clear),
|
|
onPressed: () {
|
|
query = '';
|
|
},
|
|
),
|
|
];
|
|
}
|
|
|
|
@override
|
|
Widget? buildLeading(BuildContext context) {
|
|
return IconButton(
|
|
icon: Icon(Icons.arrow_back),
|
|
onPressed: () {
|
|
close(context, '');
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget buildResults(BuildContext context) {
|
|
return Center(
|
|
child: Text('Search result for: $query'),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget buildSuggestions(BuildContext context) {
|
|
final filteredSuggestions = suggestions
|
|
.where((suggestion) => suggestion.toLowerCase().contains(query.toLowerCase()))
|
|
.toList();
|
|
|
|
return ListView.builder(
|
|
itemCount: filteredSuggestions.length,
|
|
itemBuilder: (context, index) {
|
|
final suggestion = filteredSuggestions[index];
|
|
return ListTile(
|
|
title: Text(suggestion),
|
|
onTap: () {
|
|
query = suggestion;
|
|
showResults(context);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
} |