11import 'package:flutter/material.dart' ;
22import 'package:watch_it/watch_it.dart' ;
3+ import 'package:yaru/icons.dart' ;
34
45import '../../common/chat_manager.dart' ;
6+ import '../../common/view/theme.dart' ;
57import '../../common/view/ui_constants.dart' ;
68import '../../l10n/l10n.dart' ;
79
8- class ChatRoomsSearchField extends StatelessWidget {
10+ class ChatRoomsSearchField extends StatefulWidget {
911 const ChatRoomsSearchField ({super .key});
1012
13+ @override
14+ State <ChatRoomsSearchField > createState () => _ChatRoomsSearchFieldState ();
15+ }
16+
17+ class _ChatRoomsSearchFieldState extends State <ChatRoomsSearchField > {
18+ final TextEditingController _controller = TextEditingController ();
19+
20+ @override
21+ void initState () {
22+ super .initState ();
23+ if (di <ChatManager >().filteredRoomsQuery != null ) {
24+ _controller.text = di <ChatManager >().filteredRoomsQuery! ;
25+ }
26+ }
27+
28+ @override
29+ void dispose () {
30+ _controller.dispose ();
31+ super .dispose ();
32+ }
33+
1134 @override
1235 Widget build (BuildContext context) => Padding (
1336 padding: const EdgeInsets .only (
@@ -16,10 +39,19 @@ class ChatRoomsSearchField extends StatelessWidget {
1639 bottom: kMediumPadding,
1740 ),
1841 child: TextField (
42+ controller: _controller,
1943 onChanged: di <ChatManager >().setFilteredRoomsQuery,
2044 decoration: InputDecoration (
2145 hintText: context.l10n.search,
2246 label: Text (context.l10n.search),
47+ suffixIcon: IconButton (
48+ style: textFieldSuffixStyle,
49+ onPressed: () {
50+ _controller.clear ();
51+ di <ChatManager >().setFilteredRoomsQuery (null );
52+ },
53+ icon: const Icon (YaruIcons .edit_clear),
54+ ),
2355 ),
2456 autofocus: true ,
2557 ),
0 commit comments