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.

133 lines
4.4 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<NotesBloc, List<NextcloudNotesNote>>(
stream: bloc.notes,
builder: (final context, final notes) => Scaffold(
2 years ago
resizeToAvoidBottomInset: false,
floatingActionButton: FloatingActionButton(
onPressed: () async {
final result = await showDialog<List>(
context: context,
builder: (final context) => NotesCreateNoteDialog(
bloc: bloc,
category: category,
),
);
if (result != null) {
bloc.createNote(
title: result[0] as String,
category: result[1] as String? ?? '',
2 years ago
);
}
},
child: const Icon(Icons.add),
),
body: SortBoxBuilder<NotesSortProperty, NextcloudNotesNote>(
sortBox: notesSortBox,
sortPropertyOption: bloc.options.notesSortPropertyOption,
sortBoxOrderOption: bloc.options.notesSortBoxOrderOption,
input: category != null
? notes.data?.where((final note) => note.favorite && note.category == category).toList()
: notes.data?.where((final note) => note.favorite).toList(),
builder: (final context, final sortedFavorites) => SortBoxBuilder<NotesSortProperty, NextcloudNotesNote>(
sortBox: notesSortBox,
sortPropertyOption: bloc.options.notesSortPropertyOption,
sortBoxOrderOption: bloc.options.notesSortBoxOrderOption,
input: category != null
? notes.data?.where((final note) => !note.favorite && note.category == category).toList()
: notes.data?.where((final note) => !note.favorite).toList(),
builder: (final context, final sortedNonFavorites) => NeonListView<NextcloudNotesNote>(
scrollKey: 'notes-notes',
withFloatingActionButton: true,
items: [
...?sortedFavorites,
...?sortedNonFavorites,
2 years ago
],
isLoading: notes.loading,
error: notes.error,
onRefresh: bloc.refresh,
builder: _buildNote,
),
2 years ago
),
),
),
);
Widget _buildNote(
final BuildContext context,
final NextcloudNotesNote 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 != '') ...[
2 years ago
const SizedBox(
width: 8,
),
Icon(
MdiIcons.tag,
size: 14,
color: NotesCategoryColor.compute(note.category),
2 years ago
),
const SizedBox(
width: 2,
),
Text(note.category),
2 years ago
],
],
),
trailing: IconButton(
icon: Icon(
note.favorite ? Icons.star : Icons.star_outline,
2 years ago
color: Theme.of(context).colorScheme.primary,
),
onPressed: () {
bloc.updateNote(
note.id,
note.etag,
favorite: !note.favorite,
2 years ago
);
},
),
onTap: () async {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (final context) => NotesNotePage(
bloc: NotesNoteBloc(
bloc.options,
Provider.of<AccountsBloc>(context, listen: false).activeAccount.value!.client,
bloc,
note,
),
notesBloc: bloc,
2 years ago
),
),
);
},
onLongPress: () async {
final result = await showConfirmationDialog(
context,
AppLocalizations.of(context).notesDeleteNoteConfirm(note.title),
2 years ago
);
if (result) {
bloc.deleteNote(note.id);
2 years ago
}
},
);
}