mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-08-06 15:21:21 +08:00

This allows you to long press on a note and select it, thereby allowing you to perform actions on it, without opening the note. This is disabled for note, as it isn't completely implemented. I'm not sure how to pass down the informatin on which Note is selected.
91 lines
2.3 KiB
Dart
91 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:gitjournal/core/note.dart';
|
|
import 'package:gitjournal/core/virtual_notes_folder.dart';
|
|
import 'package:gitjournal/folder_views/common.dart';
|
|
import 'package:gitjournal/folder_views/standard_view.dart';
|
|
import 'package:gitjournal/themes.dart';
|
|
|
|
class NoteSearchDelegate extends SearchDelegate<Note> {
|
|
final List<Note> notes;
|
|
final FolderViewType viewType;
|
|
|
|
NoteSearchDelegate(this.notes, this.viewType);
|
|
|
|
// 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<Widget> buildActions(BuildContext context) {
|
|
return [
|
|
IconButton(
|
|
icon: const Icon(Icons.close),
|
|
onPressed: () {
|
|
if (query.isEmpty) {
|
|
close(context, null);
|
|
} else {
|
|
query = '';
|
|
}
|
|
},
|
|
),
|
|
];
|
|
}
|
|
|
|
@override
|
|
Widget buildLeading(BuildContext context) {
|
|
return IconButton(
|
|
icon: const Icon(Icons.arrow_back),
|
|
onPressed: () {
|
|
close(context, null);
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget buildResults(BuildContext context) {
|
|
return buildView(context, query);
|
|
}
|
|
|
|
@override
|
|
Widget buildSuggestions(BuildContext context) {
|
|
return buildView(context, query);
|
|
}
|
|
|
|
Widget buildView(BuildContext context, String query) {
|
|
// TODO: This should be made far more efficient
|
|
var q = query.toLowerCase();
|
|
var filteredNotes = notes.where((note) {
|
|
if (note.title.toLowerCase().contains(q)) {
|
|
return true;
|
|
}
|
|
if (note.fileName.toLowerCase().contains(q)) {
|
|
return true;
|
|
}
|
|
return note.body.toLowerCase().contains(q);
|
|
}).toList();
|
|
|
|
var folder = VirtualNotesFolder(filteredNotes);
|
|
const emptyText = "No Search Results Found";
|
|
|
|
return buildFolderView(
|
|
viewType: viewType,
|
|
folder: folder,
|
|
emptyText: emptyText,
|
|
header: StandardViewHeader.TitleOrFileName,
|
|
showSummary: true,
|
|
noteTapped: (Note note) => openNoteEditor(context, note),
|
|
noteLongPressed: (Note note) {},
|
|
);
|
|
}
|
|
}
|