diff --git a/lib/screens/journal_listing.dart b/lib/screens/journal_listing.dart index 4106f85b..084c7c6a 100644 --- a/lib/screens/journal_listing.dart +++ b/lib/screens/journal_listing.dart @@ -1,14 +1,13 @@ import 'package:flutter/material.dart'; -import 'package:gitjournal/core/note.dart'; import 'package:gitjournal/core/notes_folder.dart'; import 'package:gitjournal/screens/note_editor.dart'; import 'package:gitjournal/state_container.dart'; import 'package:gitjournal/widgets/app_drawer.dart'; import 'package:gitjournal/widgets/app_bar_menu_button.dart'; import 'package:gitjournal/widgets/journal_list.dart'; +import 'package:gitjournal/widgets/note_search_delegate.dart'; import 'package:gitjournal/widgets/sync_button.dart'; -import 'package:gitjournal/themes.dart'; class JournalListingScreen extends StatelessWidget { final NotesFolder notesFolder; @@ -54,7 +53,7 @@ class JournalListingScreen extends StatelessWidget { onPressed: () { showSearch( context: context, - delegate: NoteSearch(allNotes), + delegate: NoteSearchDelegate(allNotes), ); }, ), @@ -82,75 +81,3 @@ class JournalListingScreen extends StatelessWidget { Navigator.of(context).push(route); } } - -class NoteSearch extends SearchDelegate { - final List notes; - - NoteSearch(this.notes); - - // Workaround because of https://github.com/flutter/flutter/issues/32180 - @override - ThemeData appBarTheme(BuildContext context) { - var theme = Theme.of(context); - if (theme.brightness == Brightness.light) { - return theme; - } - - return theme.copyWith( - primaryColor: Themes.dark.primaryColor, - ); - } - - @override - List buildActions(BuildContext context) { - return [ - IconButton( - icon: Icon(Icons.close), - onPressed: () { - query = ''; - }, - ), - ]; - } - - @override - Widget buildLeading(BuildContext context) { - return IconButton( - icon: const Icon(Icons.arrow_back), - onPressed: () { - close(context, null); - }, - ); - } - - @override - Widget buildResults(BuildContext context) { - return buildJournalList(context, query); - } - - @override - Widget buildSuggestions(BuildContext context) { - return buildJournalList(context, query); - } - - JournalList buildJournalList(BuildContext context, String query) { - // TODO: This should be made far more efficient - var q = query.toLowerCase(); - var filteredNotes = notes.where((note) { - return note.body.toLowerCase().contains(q); - }).toList(); - - Widget journalList = JournalList( - notes: filteredNotes, - noteSelectedFunction: (noteIndex) { - var note = filteredNotes[noteIndex]; - var route = MaterialPageRoute( - builder: (context) => NoteEditor.fromNote(note), - ); - Navigator.of(context).push(route); - }, - emptyText: "No Search Results Found", - ); - return journalList; - } -} diff --git a/lib/widgets/note_search_delegate.dart b/lib/widgets/note_search_delegate.dart new file mode 100644 index 00000000..def235b9 --- /dev/null +++ b/lib/widgets/note_search_delegate.dart @@ -0,0 +1,78 @@ +import 'package:flutter/material.dart'; + +import 'package:gitjournal/core/note.dart'; +import 'package:gitjournal/screens/note_editor.dart'; +import 'package:gitjournal/themes.dart'; +import 'package:gitjournal/widgets/journal_list.dart'; + +class NoteSearchDelegate extends SearchDelegate { + final List notes; + + NoteSearchDelegate(this.notes); + + // Workaround because of https://github.com/flutter/flutter/issues/32180 + @override + ThemeData appBarTheme(BuildContext context) { + var theme = Theme.of(context); + if (theme.brightness == Brightness.light) { + return theme; + } + + return theme.copyWith( + primaryColor: Themes.dark.primaryColor, + ); + } + + @override + List buildActions(BuildContext context) { + return [ + IconButton( + icon: Icon(Icons.close), + onPressed: () { + query = ''; + }, + ), + ]; + } + + @override + Widget buildLeading(BuildContext context) { + return IconButton( + icon: const Icon(Icons.arrow_back), + onPressed: () { + close(context, null); + }, + ); + } + + @override + Widget buildResults(BuildContext context) { + return buildJournalList(context, query); + } + + @override + Widget buildSuggestions(BuildContext context) { + return buildJournalList(context, query); + } + + JournalList buildJournalList(BuildContext context, String query) { + // TODO: This should be made far more efficient + var q = query.toLowerCase(); + var filteredNotes = notes.where((note) { + return note.body.toLowerCase().contains(q); + }).toList(); + + Widget journalList = JournalList( + notes: filteredNotes, + noteSelectedFunction: (noteIndex) { + var note = filteredNotes[noteIndex]; + var route = MaterialPageRoute( + builder: (context) => NoteEditor.fromNote(note), + ); + Navigator.of(context).push(route); + }, + emptyText: "No Search Results Found", + ); + return journalList; + } +}