mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-09 22:07:53 -06:00
feat: Update translations, finish saved views rework, some other fixes
This commit is contained in:
@@ -2,15 +2,16 @@ import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/repository/label_repository.dart';
|
||||
import 'package:paperless_mobile/core/widgets/dialog_utils/dialog_cancel_button.dart';
|
||||
import 'package:paperless_mobile/core/widgets/dialog_utils/dialog_confirm_button.dart';
|
||||
import 'package:paperless_mobile/core/widgets/dialog_utils/pop_with_unsaved_changes.dart';
|
||||
import 'package:paperless_mobile/features/edit_label/cubit/edit_label_cubit.dart';
|
||||
import 'package:paperless_mobile/features/edit_label/view/label_form.dart';
|
||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||
|
||||
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
||||
|
||||
class EditLabelPage<T extends Label> extends StatelessWidget {
|
||||
@@ -56,8 +57,9 @@ class EditLabelForm<T extends Label> extends StatelessWidget {
|
||||
final Future<T> Function(BuildContext context, T label) onSubmit;
|
||||
final Future<void> Function(BuildContext context, T label) onDelete;
|
||||
final bool canDelete;
|
||||
final _formKey = GlobalKey<FormBuilderState>();
|
||||
|
||||
const EditLabelForm({
|
||||
EditLabelForm({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.fromJsonT,
|
||||
@@ -69,26 +71,32 @@ class EditLabelForm<T extends Label> extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(S.of(context)!.edit),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: canDelete ? () => _onDelete(context) : null,
|
||||
icon: const Icon(Icons.delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: LabelForm<T>(
|
||||
autofocusNameField: false,
|
||||
initialValue: label,
|
||||
fromJsonT: fromJsonT,
|
||||
submitButtonConfig: SubmitButtonConfig<T>(
|
||||
icon: const Icon(Icons.save),
|
||||
label: Text(S.of(context)!.saveChanges),
|
||||
onSubmit: (label) => onSubmit(context, label),
|
||||
return PopWithUnsavedChanges(
|
||||
hasChangesPredicate: () {
|
||||
return _formKey.currentState?.isDirty ?? false;
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(S.of(context)!.edit),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: canDelete ? () => _onDelete(context) : null,
|
||||
icon: const Icon(Icons.delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: LabelForm<T>(
|
||||
formKey: _formKey,
|
||||
autofocusNameField: false,
|
||||
initialValue: label,
|
||||
fromJsonT: fromJsonT,
|
||||
submitButtonConfig: SubmitButtonConfig<T>(
|
||||
icon: const Icon(Icons.save),
|
||||
label: Text(S.of(context)!.saveChanges),
|
||||
onSubmit: (label) => onSubmit(context, label),
|
||||
),
|
||||
additionalFields: additionalFields,
|
||||
),
|
||||
additionalFields: additionalFields,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/database/tables/local_user_account.dart';
|
||||
import 'package:paperless_mobile/core/translation/matching_algorithm_localization_mapper.dart';
|
||||
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
||||
import 'package:paperless_mobile/features/home/view/model/api_version.dart';
|
||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||
|
||||
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
||||
|
||||
class SubmitButtonConfig<T extends Label> {
|
||||
@@ -36,6 +33,7 @@ class LabelForm<T extends Label> extends StatefulWidget {
|
||||
final List<Widget> additionalFields;
|
||||
|
||||
final bool autofocusNameField;
|
||||
final GlobalKey<FormBuilderState>? formKey;
|
||||
|
||||
const LabelForm({
|
||||
Key? key,
|
||||
@@ -44,6 +42,7 @@ class LabelForm<T extends Label> extends StatefulWidget {
|
||||
this.additionalFields = const [],
|
||||
required this.submitButtonConfig,
|
||||
required this.autofocusNameField,
|
||||
this.formKey,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@@ -51,7 +50,7 @@ class LabelForm<T extends Label> extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
|
||||
final _formKey = GlobalKey<FormBuilderState>();
|
||||
late final GlobalKey<FormBuilderState> _formKey;
|
||||
|
||||
late bool _enableMatchFormField;
|
||||
|
||||
@@ -60,6 +59,7 @@ class _LabelFormState<T extends Label> extends State<LabelForm<T>> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_formKey = widget.formKey ?? GlobalKey<FormBuilderState>();
|
||||
var matchingAlgorithm = (widget.initialValue?.matchingAlgorithm ??
|
||||
MatchingAlgorithm.defaultValue);
|
||||
_enableMatchFormField = matchingAlgorithm != MatchingAlgorithm.auto &&
|
||||
|
||||
Reference in New Issue
Block a user