feat: Add hive type adapters to api models, migrate to freezed

This commit is contained in:
Anton Stubenbord
2023-04-24 01:14:20 +02:00
parent 5c0ef7f853
commit 1f335119b3
67 changed files with 2075 additions and 1079 deletions

View File

@@ -8,8 +8,7 @@ import 'package:paperless_mobile/features/document_bulk_action/cubit/document_bu
import 'package:paperless_mobile/features/labels/view/widgets/label_form_field.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
typedef LabelOptionsSelector<T extends Label> = Map<int, T> Function(
DocumentBulkActionState state);
typedef LabelOptionsSelector<T extends Label> = Map<int, T> Function(DocumentBulkActionState state);
class BulkEditLabelBottomSheet<T extends Label> extends StatefulWidget {
final String title;
@@ -18,7 +17,7 @@ class BulkEditLabelBottomSheet<T extends Label> extends StatefulWidget {
final LabelOptionsSelector<T> availableOptionsSelector;
final void Function(int? selectedId) onSubmit;
final int? initialValue;
const BulkEditLabelBottomSheet({
super.key,
required this.title,
@@ -30,19 +29,16 @@ class BulkEditLabelBottomSheet<T extends Label> extends StatefulWidget {
});
@override
State<BulkEditLabelBottomSheet<T>> createState() =>
_BulkEditLabelBottomSheetState<T>();
State<BulkEditLabelBottomSheet<T>> createState() => _BulkEditLabelBottomSheetState<T>();
}
class _BulkEditLabelBottomSheetState<T extends Label>
extends State<BulkEditLabelBottomSheet<T>> {
class _BulkEditLabelBottomSheetState<T extends Label> extends State<BulkEditLabelBottomSheet<T>> {
final _formKey = GlobalKey<FormBuilderState>();
@override
Widget build(BuildContext context) {
return Padding(
padding:
EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: BlocBuilder<DocumentBulkActionCubit, DocumentBulkActionState>(
builder: (context, state) {
return Padding(
@@ -59,8 +55,7 @@ class _BulkEditLabelBottomSheetState<T extends Label>
FormBuilder(
key: _formKey,
child: LabelFormField<T>(
initialValue:
IdQueryParameter.fromId(widget.initialValue),
initialValue: IdQueryParameter.fromId(widget.initialValue),
name: "labelFormField",
options: widget.availableOptionsSelector(state),
labelText: widget.formFieldLabel,
@@ -75,12 +70,11 @@ class _BulkEditLabelBottomSheetState<T extends Label>
const SizedBox(width: 16),
FilledButton(
onPressed: () {
if (_formKey.currentState?.saveAndValidate() ??
false) {
final value = _formKey.currentState
?.getRawValue('labelFormField')
if (_formKey.currentState?.saveAndValidate() ?? false) {
final value = _formKey.currentState?.getRawValue('labelFormField')
as IdQueryParameter?;
widget.onSubmit(value?.id);
widget
.onSubmit(value?.maybeWhen(fromId: (id) => id, orElse: () => null));
}
},
child: Text(S.of(context)!.apply),