A framework for building convergent cross-platform Nextcloud clients using Flutter.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
3.1 KiB

part of '../neon_notes.dart';
2 years ago
class NotesView extends StatelessWidget {
const NotesView({
required this.bloc,
this.category,
super.key,
});
final NotesBloc bloc;
final String? category;
@override
Widget build(final BuildContext context) => ResultBuilder<List<notes.Note>>.behaviorSubject(
stream: bloc.notesList,
builder: (final context, final notesList) => SortBoxBuilder<NotesSortProperty, notes.Note>(
sortBox: notesSortBox,
presort: const {
(NotesSortProperty.favorite, SortBoxOrder.ascending),
},
sortProperty: bloc.options.notesSortPropertyOption,
sortBoxOrder: bloc.options.notesSortBoxOrderOption,
input: category != null
? notesList.data?.where((final note) => note.category == category).toList()
: notesList.data,
builder: (final context, final sorted) => NeonListView(
scrollKey: 'notes-notes',
isLoading: notesList.isLoading,
error: notesList.error,
onRefresh: bloc.refresh,
itemCount: sorted.length,
itemBuilder: (final context, final index) => _buildNote(context, sorted[index]),
2 years ago
),
),
);
Widget _buildNote(
final BuildContext context,
final notes.Note note,
2 years ago
) =>
ListTile(
title: Text(note.title),
2 years ago
subtitle: Row(
children: [
RelativeTime(
date: DateTime.fromMillisecondsSinceEpoch(note.modified * 1000),
2 years ago
),
if (note.category.isNotEmpty) ...[
2 years ago
const SizedBox(
width: 8,
),
Icon(
MdiIcons.tag,
size: smallIconSize,
color: NotesCategoryColor.compute(note.category),
2 years ago
),
const SizedBox(
width: 2,
),
Text(note.category),
2 years ago
],
],
),
trailing: IconButton(
onPressed: () {
bloc.updateNote(
note.id,
note.etag,
favorite: !note.favorite,
2 years ago
);
},
tooltip: note.favorite ? NotesLocalizations.of(context).noteUnstar : NotesLocalizations.of(context).noteStar,
icon: Icon(
note.favorite ? Icons.star : Icons.star_outline,
color: Theme.of(context).colorScheme.primary,
),
2 years ago
),
onTap: () async {
await Navigator.of(context).push(
MaterialPageRoute<void>(
2 years ago
builder: (final context) => NotesNotePage(
bloc: NotesNoteBloc(
bloc,
note,
),
notesBloc: bloc,
2 years ago
),
),
);
},
onLongPress: () async {
final result = await showConfirmationDialog(
context,
NotesLocalizations.of(context).noteDeleteConfirm(note.title),
2 years ago
);
if (result) {
bloc.deleteNote(note.id);
2 years ago
}
},
);
}