Browse Source

neon_notes: get blocs via context

pull/377/head
Nikolas Rimikis 2 years ago
parent
commit
b003ab9df5
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 15
      packages/neon/neon_notes/lib/dialogs/create_note.dart
  2. 14
      packages/neon/neon_notes/lib/dialogs/select_category.dart
  3. 4
      packages/neon/neon_notes/lib/pages/category.dart
  4. 14
      packages/neon/neon_notes/lib/pages/main.dart
  5. 6
      packages/neon/neon_notes/lib/pages/note.dart
  6. 10
      packages/neon/neon_notes/lib/widgets/categories_view.dart
  7. 9
      packages/neon/neon_notes/lib/widgets/notes_floating_action_button.dart
  8. 15
      packages/neon/neon_notes/lib/widgets/notes_view.dart

15
packages/neon/neon_notes/lib/dialogs/create_note.dart

@ -2,12 +2,10 @@ part of '../neon_notes.dart';
class NotesCreateNoteDialog extends StatefulWidget {
const NotesCreateNoteDialog({
required this.bloc,
this.category,
super.key,
});
final NotesBloc bloc;
final String? category;
@override
@ -17,8 +15,17 @@ class NotesCreateNoteDialog extends StatefulWidget {
class _NotesCreateNoteDialogState extends State<NotesCreateNoteDialog> {
final formKey = GlobalKey<FormState>();
final controller = TextEditingController();
late NotesBloc bloc;
String? selectedCategory;
@override
void initState() {
bloc = Provider.of<NotesBloc>(context, listen: false);
super.initState();
}
void submit() {
if (formKey.currentState!.validate()) {
Navigator.of(context).pop([controller.text, widget.category ?? selectedCategory]);
@ -27,7 +34,7 @@ class _NotesCreateNoteDialogState extends State<NotesCreateNoteDialog> {
@override
Widget build(final BuildContext context) => ResultBuilder<List<NextcloudNotesNote>>(
stream: widget.bloc.notes,
stream: bloc.notes,
builder: (final context, final notes) => NeonDialog(
title: Text(AppLocalizations.of(context).noteCreate),
children: [
@ -51,7 +58,7 @@ class _NotesCreateNoteDialogState extends State<NotesCreateNoteDialog> {
Center(
child: NeonException(
notes.error,
onRetry: widget.bloc.refresh,
onRetry: bloc.refresh,
),
),
Center(

14
packages/neon/neon_notes/lib/dialogs/select_category.dart

@ -2,12 +2,10 @@ part of '../neon_notes.dart';
class NotesSelectCategoryDialog extends StatefulWidget {
const NotesSelectCategoryDialog({
required this.bloc,
this.initialCategory,
super.key,
});
final NotesBloc bloc;
final String? initialCategory;
@override
@ -16,9 +14,17 @@ class NotesSelectCategoryDialog extends StatefulWidget {
class _NotesSelectCategoryDialogState extends State<NotesSelectCategoryDialog> {
final formKey = GlobalKey<FormState>();
late NotesBloc bloc;
String? selectedCategory;
@override
void initState() {
bloc = Provider.of<NotesBloc>(context, listen: false);
super.initState();
}
void submit() {
if (formKey.currentState!.validate()) {
Navigator.of(context).pop(selectedCategory);
@ -27,7 +33,7 @@ class _NotesSelectCategoryDialogState extends State<NotesSelectCategoryDialog> {
@override
Widget build(final BuildContext context) => ResultBuilder<List<NextcloudNotesNote>>(
stream: widget.bloc.notes,
stream: bloc.notes,
builder: (final context, final notes) => NeonDialog(
title: Text(AppLocalizations.of(context).category),
children: [
@ -39,7 +45,7 @@ class _NotesSelectCategoryDialogState extends State<NotesSelectCategoryDialog> {
Center(
child: NeonException(
notes.error,
onRetry: widget.bloc.refresh,
onRetry: bloc.refresh,
),
),
Center(

4
packages/neon/neon_notes/lib/pages/category.dart

@ -2,12 +2,10 @@ part of '../neon_notes.dart';
class NotesCategoryPage extends StatelessWidget {
const NotesCategoryPage({
required this.bloc,
required this.category,
super.key,
});
final NotesBloc bloc;
final NoteCategory category;
@override
@ -17,11 +15,9 @@ class NotesCategoryPage extends StatelessWidget {
title: Text(category.name != '' ? category.name : AppLocalizations.of(context).categoryUncategorized),
),
body: NotesView(
bloc: bloc,
category: category.name,
),
floatingActionButton: NotesFloatingActionButton(
bloc: bloc,
category: category.name,
),
);

14
packages/neon/neon_notes/lib/pages/main.dart

@ -26,17 +26,13 @@ class _NotesMainPageState extends State<NotesMainPage> {
@override
Widget build(final BuildContext context) {
final views = [
NotesView(
bloc: bloc,
),
NotesCategoriesView(
bloc: bloc,
),
const views = [
NotesView(),
NotesCategoriesView(),
];
final floatingActionButtons = [
NotesFloatingActionButton(bloc: bloc),
const floatingActionButtons = [
NotesFloatingActionButton(),
null,
];

6
packages/neon/neon_notes/lib/pages/note.dart

@ -3,18 +3,17 @@ part of '../neon_notes.dart';
class NotesNotePage extends StatefulWidget {
const NotesNotePage({
required this.bloc,
required this.notesBloc,
super.key,
});
final NotesNoteBloc bloc;
final NotesBloc notesBloc;
@override
State<NotesNotePage> createState() => _NotesNotePageState();
}
class _NotesNotePageState extends State<NotesNotePage> {
late NotesBloc notesBloc;
late final _contentController = TextEditingController()..text = widget.bloc.initialContent;
late final _titleController = TextEditingController()..text = widget.bloc.initialTitle;
final _contentFocusNode = FocusNode();
@ -32,6 +31,8 @@ class _NotesNotePageState extends State<NotesNotePage> {
void initState() {
super.initState();
notesBloc = Provider.of<NotesBloc>(context, listen: false);
widget.bloc.errors.listen((final error) {
handleNotesException(context, error);
});
@ -118,7 +119,6 @@ class _NotesNotePageState extends State<NotesNotePage> {
final result = await showDialog<String>(
context: context,
builder: (final context) => NotesSelectCategoryDialog(
bloc: widget.notesBloc,
initialCategory: category,
),
);

10
packages/neon/neon_notes/lib/widgets/categories_view.dart

@ -2,14 +2,14 @@ part of '../neon_notes.dart';
class NotesCategoriesView extends StatelessWidget {
const NotesCategoriesView({
required this.bloc,
super.key,
});
final NotesBloc bloc;
@override
Widget build(final BuildContext context) => ResultBuilder<List<NextcloudNotesNote>>(
Widget build(final BuildContext context) {
final bloc = Provider.of<NotesBloc>(context, listen: false);
return ResultBuilder<List<NextcloudNotesNote>>(
stream: bloc.notes,
builder: (final context, final notes) => SortBoxBuilder<CategoriesSortProperty, NoteCategory>(
sortBox: categoriesSortBox,
@ -35,6 +35,7 @@ class NotesCategoriesView extends StatelessWidget {
),
),
);
}
Widget _buildCategory(
final BuildContext context,
@ -54,7 +55,6 @@ class NotesCategoriesView extends StatelessWidget {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (final context) => NotesCategoryPage(
bloc: bloc,
category: category,
),
),

9
packages/neon/neon_notes/lib/widgets/notes_floating_action_button.dart

@ -2,21 +2,21 @@ part of '../neon_notes.dart';
class NotesFloatingActionButton extends StatelessWidget {
const NotesFloatingActionButton({
required this.bloc,
this.category,
super.key,
});
final NotesBloc bloc;
final String? category;
@override
Widget build(final BuildContext context) => FloatingActionButton(
Widget build(final BuildContext context) {
final bloc = Provider.of<NotesBloc>(context, listen: false);
return FloatingActionButton(
onPressed: () async {
final result = await showDialog<List>(
context: context,
builder: (final context) => NotesCreateNoteDialog(
bloc: bloc,
category: category,
),
);
@ -30,4 +30,5 @@ class NotesFloatingActionButton extends StatelessWidget {
tooltip: AppLocalizations.of(context).noteCreate,
child: const Icon(Icons.add),
);
}
}

15
packages/neon/neon_notes/lib/widgets/notes_view.dart

@ -2,16 +2,16 @@ part of '../neon_notes.dart';
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<NextcloudNotesNote>>(
Widget build(final BuildContext context) {
final bloc = Provider.of<NotesBloc>(context, listen: false);
return ResultBuilder<List<NextcloudNotesNote>>(
stream: bloc.notes,
builder: (final context, final notes) => SortBoxBuilder<NotesSortProperty, NextcloudNotesNote>(
sortBox: notesSortBox,
@ -42,12 +42,15 @@ class NotesView extends StatelessWidget {
),
),
);
}
Widget _buildNote(
final BuildContext context,
final NextcloudNotesNote note,
) =>
ListTile(
) {
final bloc = Provider.of<NotesBloc>(context, listen: false);
return ListTile(
title: Text(note.title),
subtitle: Row(
children: [
@ -94,7 +97,6 @@ class NotesView extends StatelessWidget {
bloc,
note,
),
notesBloc: bloc,
),
),
);
@ -109,4 +111,5 @@ class NotesView extends StatelessWidget {
}
},
);
}
}

Loading…
Cancel
Save