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.
83 lines
2.7 KiB
83 lines
2.7 KiB
2 years ago
|
part of '../neon_notes.dart';
|
||
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;
|
||
|
|
||
|
void submit() {
|
||
|
if (formKey.currentState!.validate()) {
|
||
|
Navigator.of(context).pop([controller.text, widget.category ?? selectedCategory]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@override
|
||
2 years ago
|
Widget build(final BuildContext context) => ResultBuilder<NotesBloc, List<NextcloudNotesNote>>(
|
||
2 years ago
|
stream: widget.bloc.notes,
|
||
|
builder: (final context, final notes) => CustomDialog(
|
||
2 years ago
|
title: Text(AppLocalizations.of(context).notesCreateNote),
|
||
|
children: [
|
||
|
Form(
|
||
|
key: formKey,
|
||
|
child: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.end,
|
||
|
children: [
|
||
|
TextFormField(
|
||
|
autofocus: true,
|
||
|
controller: controller,
|
||
|
decoration: InputDecoration(
|
||
|
hintText: AppLocalizations.of(context).notesNoteTitle,
|
||
|
),
|
||
|
validator: (final input) => validateNotEmpty(context, input),
|
||
|
onFieldSubmitted: (final _) {
|
||
|
submit();
|
||
|
},
|
||
|
),
|
||
|
if (widget.category == null) ...[
|
||
|
Center(
|
||
|
child: ExceptionWidget(
|
||
2 years ago
|
notes.error,
|
||
2 years ago
|
onRetry: widget.bloc.refresh,
|
||
2 years ago
|
),
|
||
|
),
|
||
|
Center(
|
||
|
child: CustomLinearProgressIndicator(
|
||
2 years ago
|
visible: notes.loading,
|
||
2 years ago
|
),
|
||
|
),
|
||
2 years ago
|
if (notes.data != null) ...[
|
||
2 years ago
|
NotesCategorySelect(
|
||
2 years ago
|
categories: notes.data!.map((final note) => note.category).toSet().toList(),
|
||
2 years ago
|
onChanged: (final category) {
|
||
|
selectedCategory = category;
|
||
|
},
|
||
|
onSubmitted: submit,
|
||
|
),
|
||
|
],
|
||
|
],
|
||
|
ElevatedButton(
|
||
|
onPressed: submit,
|
||
|
child: Text(AppLocalizations.of(context).notesCreateNote),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
}
|