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.
164 lines
5.1 KiB
164 lines
5.1 KiB
1 year ago
|
import 'package:flutter/material.dart';
|
||
|
import 'package:neon/blocs.dart';
|
||
|
import 'package:neon/utils.dart';
|
||
|
import 'package:neon/widgets.dart';
|
||
|
import 'package:neon_notes/l10n/localizations.dart';
|
||
|
import 'package:neon_notes/neon_notes.dart';
|
||
|
import 'package:nextcloud/notes.dart' as notes;
|
||
2 years ago
|
|
||
|
class NotesCreateNoteDialog extends StatefulWidget {
|
||
|
const NotesCreateNoteDialog({
|
||
|
required this.bloc,
|
||
|
this.category,
|
||
|
super.key,
|
||
|
});
|
||
|
|
||
|
final NotesBloc bloc;
|
||
|
final String? category;
|
||
|
|
||
|
@override
|
||
|
State<NotesCreateNoteDialog> createState() => _NotesCreateNoteDialogState();
|
||
|
}
|
||
|
|
||
|
class _NotesCreateNoteDialogState extends State<NotesCreateNoteDialog> {
|
||
|
final formKey = GlobalKey<FormState>();
|
||
|
final controller = TextEditingController();
|
||
|
String? selectedCategory;
|
||
|
|
||
1 year ago
|
@override
|
||
|
void dispose() {
|
||
|
controller.dispose();
|
||
|
super.dispose();
|
||
|
}
|
||
|
|
||
2 years ago
|
void submit() {
|
||
|
if (formKey.currentState!.validate()) {
|
||
1 year ago
|
Navigator.of(context).pop((controller.text, widget.category ?? selectedCategory));
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
@override
|
||
1 year ago
|
Widget build(final BuildContext context) => ResultBuilder<List<notes.Note>>.behaviorSubject(
|
||
1 year ago
|
subject: widget.bloc.notesList,
|
||
2 years ago
|
builder: (final context, final notes) => NeonDialog(
|
||
1 year ago
|
title: Text(NotesLocalizations.of(context).noteCreate),
|
||
2 years ago
|
children: [
|
||
|
Form(
|
||
|
key: formKey,
|
||
|
child: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||
|
children: [
|
||
|
TextFormField(
|
||
|
autofocus: true,
|
||
|
controller: controller,
|
||
|
decoration: InputDecoration(
|
||
1 year ago
|
hintText: NotesLocalizations.of(context).noteTitle,
|
||
2 years ago
|
),
|
||
|
validator: (final input) => validateNotEmpty(context, input),
|
||
|
onFieldSubmitted: (final _) {
|
||
|
submit();
|
||
|
},
|
||
|
),
|
||
|
if (widget.category == null) ...[
|
||
|
Center(
|
||
1 year ago
|
child: NeonError(
|
||
2 years ago
|
notes.error,
|
||
2 years ago
|
onRetry: widget.bloc.refresh,
|
||
2 years ago
|
),
|
||
|
),
|
||
|
Center(
|
||
2 years ago
|
child: NeonLinearProgressIndicator(
|
||
1 year ago
|
visible: notes.isLoading,
|
||
2 years ago
|
),
|
||
|
),
|
||
1 year ago
|
if (notes.hasData) ...[
|
||
2 years ago
|
NotesCategorySelect(
|
||
1 year ago
|
categories: notes.requireData.map((final note) => note.category).toSet().toList(),
|
||
2 years ago
|
onChanged: (final category) {
|
||
|
selectedCategory = category;
|
||
|
},
|
||
|
onSubmitted: submit,
|
||
|
),
|
||
|
],
|
||
|
],
|
||
|
ElevatedButton(
|
||
|
onPressed: submit,
|
||
1 year ago
|
child: Text(NotesLocalizations.of(context).noteCreate),
|
||
2 years ago
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
}
|
||
1 year ago
|
|
||
|
class NotesSelectCategoryDialog extends StatefulWidget {
|
||
|
const NotesSelectCategoryDialog({
|
||
|
required this.bloc,
|
||
|
this.initialCategory,
|
||
|
super.key,
|
||
|
});
|
||
|
|
||
|
final NotesBloc bloc;
|
||
|
final String? initialCategory;
|
||
|
|
||
|
@override
|
||
|
State<NotesSelectCategoryDialog> createState() => _NotesSelectCategoryDialogState();
|
||
|
}
|
||
|
|
||
|
class _NotesSelectCategoryDialogState extends State<NotesSelectCategoryDialog> {
|
||
|
final formKey = GlobalKey<FormState>();
|
||
|
|
||
|
String? selectedCategory;
|
||
|
|
||
|
void submit() {
|
||
|
if (formKey.currentState!.validate()) {
|
||
|
Navigator.of(context).pop(selectedCategory);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(final BuildContext context) => ResultBuilder<List<notes.Note>>.behaviorSubject(
|
||
|
subject: widget.bloc.notesList,
|
||
|
builder: (final context, final notes) => NeonDialog(
|
||
|
title: Text(NotesLocalizations.of(context).category),
|
||
|
children: [
|
||
|
Form(
|
||
|
key: formKey,
|
||
|
child: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||
|
children: [
|
||
|
Center(
|
||
|
child: NeonError(
|
||
|
notes.error,
|
||
|
onRetry: widget.bloc.refresh,
|
||
|
),
|
||
|
),
|
||
|
Center(
|
||
|
child: NeonLinearProgressIndicator(
|
||
|
visible: notes.isLoading,
|
||
|
),
|
||
|
),
|
||
|
if (notes.hasData) ...[
|
||
|
NotesCategorySelect(
|
||
|
categories: notes.requireData.map((final note) => note.category).toSet().toList(),
|
||
|
initialValue: widget.initialCategory,
|
||
|
onChanged: (final category) {
|
||
|
selectedCategory = category;
|
||
|
},
|
||
|
onSubmitted: submit,
|
||
|
),
|
||
|
],
|
||
|
ElevatedButton(
|
||
|
onPressed: submit,
|
||
|
child: Text(NotesLocalizations.of(context).noteSetCategory),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
}
|