@@ -48,6 +48,26 @@ class NotesScreen extends ConsumerStatefulWidget {
4848}
4949
5050class _NotesScreenState extends ConsumerState <NotesScreen > {
51+ bool _searching = false ;
52+ final _searchController = TextEditingController ();
53+ String _searchQuery = '' ;
54+
55+ @override
56+ void dispose () {
57+ _searchController.dispose ();
58+ super .dispose ();
59+ }
60+
61+ void _startSearch () => setState (() => _searching = true );
62+
63+ void _stopSearch () {
64+ setState (() {
65+ _searching = false ;
66+ _searchQuery = '' ;
67+ _searchController.clear ();
68+ });
69+ }
70+
5171 @override
5272 Widget build (BuildContext context) {
5373 final groupsValue = ref.watch (activeGroupsProvider);
@@ -57,7 +77,29 @@ class _NotesScreenState extends ConsumerState<NotesScreen> {
5777 length: 4 ,
5878 child: Scaffold (
5979 appBar: AppBar (
60- title: Text ('notes' .tr ()),
80+ title: _searching
81+ ? TextField (
82+ controller: _searchController,
83+ autofocus: true ,
84+ decoration: InputDecoration (
85+ hintText: 'search_notes' .tr (),
86+ border: InputBorder .none,
87+ ),
88+ onChanged: (v) => setState (() => _searchQuery = v),
89+ )
90+ : Text ('notes' .tr ()),
91+ actions: [
92+ if (_searching)
93+ IconButton (
94+ icon: const Icon (Icons .close),
95+ onPressed: _stopSearch,
96+ )
97+ else
98+ IconButton (
99+ icon: const Icon (Icons .search),
100+ onPressed: _startSearch,
101+ ),
102+ ],
61103 bottom: TabBar (
62104 tabs: [
63105 Tab (text: 'all' .tr ()),
@@ -80,13 +122,26 @@ class _NotesScreenState extends ConsumerState<NotesScreen> {
80122 : null ,
81123 body: TabBarView (
82124 children: [
83- _NotesList (provider: allNotesProvider, emptyKey: 'empty_notes' ),
84- _NotesList (provider: todoNotesProvider, emptyKey: 'empty_notes' ),
85- _NotesList (provider: doneNotesProvider, emptyKey: 'empty_notes' ),
125+ _NotesList (
126+ provider: allNotesProvider,
127+ emptyKey: 'empty_notes' ,
128+ searchQuery: _searchQuery,
129+ ),
130+ _NotesList (
131+ provider: todoNotesProvider,
132+ emptyKey: 'empty_notes' ,
133+ searchQuery: _searchQuery,
134+ ),
135+ _NotesList (
136+ provider: doneNotesProvider,
137+ emptyKey: 'empty_notes' ,
138+ searchQuery: _searchQuery,
139+ ),
86140 _NotesList (
87141 provider: archivedNotesProvider,
88142 emptyKey: 'empty_notes' ,
89143 archived: true ,
144+ searchQuery: _searchQuery,
90145 ),
91146 ],
92147 ),
@@ -125,11 +180,13 @@ class _NotesList extends ConsumerWidget {
125180 required this .provider,
126181 required this .emptyKey,
127182 this .archived = false ,
183+ this .searchQuery = '' ,
128184 });
129185
130186 final StreamProvider <List <TeacherNote >> provider;
131187 final String emptyKey;
132188 final bool archived;
189+ final String searchQuery;
133190
134191 @override
135192 Widget build (BuildContext context, WidgetRef ref) {
@@ -139,11 +196,23 @@ class _NotesList extends ConsumerWidget {
139196
140197 return ContentConstraints (
141198 child: notesValue.when (
142- data: (notes) {
199+ data: (allNotes) {
200+ final notes = searchQuery.isEmpty
201+ ? allNotes
202+ : allNotes
203+ .where (
204+ (n) => n.body.toLowerCase ().contains (
205+ searchQuery.toLowerCase (),
206+ ),
207+ )
208+ .toList (growable: false );
209+
143210 if (notes.isEmpty) {
144211 return EmptyState (
145212 icon: Icons .sticky_note_2_outlined,
146- title: emptyKey.tr (),
213+ title: searchQuery.isEmpty
214+ ? emptyKey.tr ()
215+ : 'no_notes_found' .tr (),
147216 );
148217 }
149218
0 commit comments