50 lines
1.4 KiB
Dart
50 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../data/chat_message_matcher.dart';
|
|
import 'chat_search_controller.dart';
|
|
import 'chat_search_results.dart';
|
|
|
|
/// Search inside one chat, built like `FilesSearchDelegate`. Closes with the
|
|
/// tapped hit so the chat can jump there.
|
|
class ChatSearchDelegate extends SearchDelegate<ChatSearchHit?> {
|
|
final ChatSearchController _controller;
|
|
|
|
ChatSearchDelegate(this._controller)
|
|
: super(searchFieldLabel: 'In Chat suchen');
|
|
|
|
/// Must be called by the host widget after `showSearch` returns so the
|
|
/// controller's listeners and pending debounce timers are released.
|
|
void disposeController() => _controller.dispose();
|
|
|
|
@override
|
|
List<Widget>? buildActions(BuildContext context) => [
|
|
if (query.isNotEmpty)
|
|
IconButton(
|
|
tooltip: 'Suche leeren',
|
|
icon: const Icon(Icons.clear),
|
|
onPressed: () {
|
|
query = '';
|
|
},
|
|
),
|
|
];
|
|
|
|
@override
|
|
Widget? buildLeading(BuildContext context) => IconButton(
|
|
icon: const Icon(Icons.arrow_back),
|
|
tooltip: 'Zurück',
|
|
onPressed: () => close(context, null),
|
|
);
|
|
|
|
@override
|
|
Widget buildResults(BuildContext context) => buildSuggestions(context);
|
|
|
|
@override
|
|
Widget buildSuggestions(BuildContext context) {
|
|
_controller.setQuery(query);
|
|
return ChatSearchResults(
|
|
controller: _controller,
|
|
onResultTap: (hit) => close(context, hit),
|
|
);
|
|
}
|
|
}
|