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.

89 lines
2.8 KiB

part of '../neon_notes.dart';
3 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;
@override
void dispose() {
controller.dispose();
super.dispose();
}
3 years ago
void submit() {
if (formKey.currentState!.validate()) {
Navigator.of(context).pop((controller.text, widget.category ?? selectedCategory));
3 years ago
}
}
@override
Widget build(final BuildContext context) => ResultBuilder<List<NotesNote>>.behaviorSubject(
stream: widget.bloc.notes,
builder: (final context, final notes) => NeonDialog(
title: Text(AppLocalizations.of(context).noteCreate),
3 years ago
children: [
Form(
key: formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
TextFormField(
autofocus: true,
controller: controller,
decoration: InputDecoration(
hintText: AppLocalizations.of(context).noteTitle,
3 years ago
),
validator: (final input) => validateNotEmpty(context, input),
onFieldSubmitted: (final _) {
submit();
},
),
if (widget.category == null) ...[
Center(
child: NeonException(
notes.error,
onRetry: widget.bloc.refresh,
3 years ago
),
),
Center(
child: NeonLinearProgressIndicator(
visible: notes.isLoading,
3 years ago
),
),
if (notes.hasData) ...[
3 years ago
NotesCategorySelect(
categories: notes.requireData.map((final note) => note.category).toSet().toList(),
3 years ago
onChanged: (final category) {
selectedCategory = category;
},
onSubmitted: submit,
),
],
],
ElevatedButton(
onPressed: submit,
child: Text(AppLocalizations.of(context).noteCreate),
3 years ago
),
],
),
),
],
),
);
}