import 'package:flutter/material.dart'; class CharacterSearchDelegate extends SearchDelegate { final List suggestions; CharacterSearchDelegate(this.suggestions); @override List? 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); }, ); }, ); } }