fix: Document upload created at field clear button only shows when value is set, consistent ordering of labels

This commit is contained in:
Anton Stubenbord
2023-02-16 11:13:37 +01:00
parent 52bb4c8b50
commit 72ce7658ed
2 changed files with 39 additions and 30 deletions

View File

@@ -8,9 +8,6 @@ import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:intl/intl.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/core/repository/label_repository.dart';
import 'package:paperless_mobile/core/repository/state/impl/correspondent_repository_state.dart';
import 'package:paperless_mobile/core/repository/state/impl/document_type_repository_state.dart';
import 'package:paperless_mobile/core/repository/state/impl/storage_path_repository_state.dart';
import 'package:paperless_mobile/core/workarounds/colored_chip.dart';
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
import 'package:paperless_mobile/features/document_edit/cubit/document_edit_cubit.dart';
@@ -21,7 +18,6 @@ import 'package:paperless_mobile/features/labels/tags/view/widgets/tags_form_fie
import 'package:paperless_mobile/features/labels/view/widgets/label_form_field.dart';
import 'package:paperless_mobile/generated/l10n.dart';
import 'package:paperless_mobile/helpers/message_helpers.dart';
import 'package:paperless_mobile/constants.dart';
class DocumentEditPage extends StatefulWidget {
final FieldSuggestions suggestions;
@@ -88,14 +84,14 @@ class _DocumentEditPageState extends State<DocumentEditPage> {
children: [
_buildTitleFormField(state.document.title).padded(),
_buildCreatedAtFormField(state.document.created).padded(),
_buildDocumentTypeFormField(
state.document.documentType,
state.documentTypes,
).padded(),
_buildCorrespondentFormField(
state.document.correspondent,
state.correspondents,
).padded(),
_buildDocumentTypeFormField(
state.document.documentType,
state.documentTypes,
).padded(),
_buildStoragePathFormField(
state.document.storagePath,
state.storagePaths,

View File

@@ -47,6 +47,7 @@ class _DocumentUploadPreparationPageState
PaperlessValidationErrors _errors = {};
bool _isUploadLoading = false;
late bool _syncTitleAndFilename;
bool _showDatePickerDeleteIcon = false;
final _now = DateTime.now();
@override
@@ -82,6 +83,7 @@ class _DocumentUploadPreparationPageState
key: _formKey,
child: ListView(
children: [
// Title
FormBuilderTextField(
autovalidateMode: AutovalidateMode.always,
name: DocumentModel.titleKey,
@@ -112,6 +114,7 @@ class _DocumentUploadPreparationPageState
}
},
),
// Filename
FormBuilderTextField(
autovalidateMode: AutovalidateMode.always,
readOnly: _syncTitleAndFilename,
@@ -129,6 +132,7 @@ class _DocumentUploadPreparationPageState
initialValue: widget.filename ??
"scan_${fileNameDateFormat.format(_now)}",
),
// Synchronize title and filename
SwitchListTile(
value: _syncTitleAndFilename,
onChanged: (value) {
@@ -152,40 +156,33 @@ class _DocumentUploadPreparationPageState
.documentUploadPageSynchronizeTitleAndFilenameLabel,
),
),
// Created at
FormBuilderDateTimePicker(
autovalidateMode: AutovalidateMode.always,
format: DateFormat.yMMMMd(),
inputType: InputType.date,
name: DocumentModel.createdKey,
initialValue: null,
onChanged: (value) {
setState(() => _showDatePickerDeleteIcon = value != null);
},
decoration: InputDecoration(
prefixIcon: const Icon(Icons.calendar_month_outlined),
labelText:
S.of(context).documentCreatedPropertyLabel + " *",
suffixIcon: IconButton(
suffixIcon: _showDatePickerDeleteIcon
? IconButton(
icon: const Icon(Icons.close),
onPressed: () {
_formKey
.currentState!.fields[DocumentModel.createdKey]
_formKey.currentState!
.fields[DocumentModel.createdKey]
?.didChange(null);
},
)),
)
: null,
),
LabelFormField<DocumentType>(
notAssignedSelectable: false,
formBuilderState: _formKey.currentState,
labelCreationWidgetBuilder: (initialName) =>
RepositoryProvider(
create: (context) =>
context.read<LabelRepository<DocumentType>>(),
child: AddDocumentTypePage(initialName: initialName),
),
textFieldLabel:
S.of(context).documentDocumentTypePropertyLabel + " *",
name: DocumentModel.documentTypeKey,
labelOptions: state.documentTypes,
prefixIcon: const Icon(Icons.description_outlined),
),
// Correspondent
LabelFormField<Correspondent>(
notAssignedSelectable: false,
formBuilderState: _formKey.currentState,
@@ -201,6 +198,22 @@ class _DocumentUploadPreparationPageState
labelOptions: state.correspondents,
prefixIcon: const Icon(Icons.person_outline),
),
// Document type
LabelFormField<DocumentType>(
notAssignedSelectable: false,
formBuilderState: _formKey.currentState,
labelCreationWidgetBuilder: (initialName) =>
RepositoryProvider(
create: (context) =>
context.read<LabelRepository<DocumentType>>(),
child: AddDocumentTypePage(initialName: initialName),
),
textFieldLabel:
S.of(context).documentDocumentTypePropertyLabel + " *",
name: DocumentModel.documentTypeKey,
labelOptions: state.documentTypes,
prefixIcon: const Icon(Icons.description_outlined),
),
TagFormField(
name: DocumentModel.tagsKey,
notAssignedSelectable: false,