mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-10 18:07:59 -06:00
Initial commit
This commit is contained in:
224
lib/features/scan/view/document_upload_page.dart
Normal file
224
lib/features/scan/view/document_upload_page.dart
Normal file
@@ -0,0 +1,224 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||
import 'package:flutter_paperless_mobile/core/model/error_message.dart';
|
||||
import 'package:flutter_paperless_mobile/di_initializer.dart';
|
||||
import 'package:flutter_paperless_mobile/extensions/flutter_extensions.dart';
|
||||
import 'package:flutter_paperless_mobile/features/documents/model/document.model.dart';
|
||||
import 'package:flutter_paperless_mobile/features/documents/model/query_parameters/correspondent_query.dart';
|
||||
import 'package:flutter_paperless_mobile/features/documents/model/query_parameters/document_type_query.dart';
|
||||
import 'package:flutter_paperless_mobile/features/documents/model/query_parameters/id_query_parameter.dart';
|
||||
import 'package:flutter_paperless_mobile/features/documents/model/query_parameters/ids_query_parameter.dart';
|
||||
import 'package:flutter_paperless_mobile/features/labels/correspondent/bloc/correspondents_cubit.dart';
|
||||
import 'package:flutter_paperless_mobile/features/labels/document_type/bloc/document_type_cubit.dart';
|
||||
import 'package:flutter_paperless_mobile/features/documents/bloc/documents_cubit.dart';
|
||||
import 'package:flutter_paperless_mobile/features/labels/correspondent/model/correspondent.model.dart';
|
||||
import 'package:flutter_paperless_mobile/features/labels/correspondent/view/pages/add_correspondent_page.dart';
|
||||
import 'package:flutter_paperless_mobile/features/labels/document_type/model/document_type.model.dart';
|
||||
import 'package:flutter_paperless_mobile/features/labels/document_type/view/pages/add_document_type_page.dart';
|
||||
import 'package:flutter_paperless_mobile/features/labels/tags/view/widgets/tags_form_field.dart';
|
||||
import 'package:flutter_paperless_mobile/features/labels/view/widgets/label_form_field.dart';
|
||||
import 'package:flutter_paperless_mobile/features/scan/bloc/document_scanner_cubit.dart';
|
||||
import 'package:flutter_paperless_mobile/generated/l10n.dart';
|
||||
import 'package:flutter_paperless_mobile/util.dart';
|
||||
import 'package:form_builder_validators/form_builder_validators.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class DocumentUploadPage extends StatefulWidget {
|
||||
final Uint8List pdfBytes;
|
||||
const DocumentUploadPage({
|
||||
Key? key,
|
||||
required this.pdfBytes,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<DocumentUploadPage> createState() => _DocumentUploadPageState();
|
||||
}
|
||||
|
||||
class _DocumentUploadPageState extends State<DocumentUploadPage> {
|
||||
static const fkFileName = "fileName";
|
||||
|
||||
static final fileNameDateFormat = DateFormat("yyyy_MM_ddTHH_mm_ss");
|
||||
final GlobalKey<FormBuilderState> _formKey = GlobalKey();
|
||||
|
||||
Map<String, String> _errors = {};
|
||||
bool _isUploadLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
initializeDateFormatting(); //TODO: INTL (has to do with intl below)
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: true,
|
||||
appBar: AppBar(
|
||||
title: Text(S.of(context).documentsUploadPageTitle),
|
||||
bottom: _isUploadLoading
|
||||
? const PreferredSize(
|
||||
child: LinearProgressIndicator(), preferredSize: Size.fromHeight(4.0))
|
||||
: null,
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: _onSubmit,
|
||||
label: Text(S.of(context).genericActionUploadLabel),
|
||||
icon: const Icon(Icons.upload),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: FormBuilder(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
FormBuilderTextField(
|
||||
autovalidateMode: AutovalidateMode.always,
|
||||
name: DocumentModel.titleKey,
|
||||
initialValue: "scan_${fileNameDateFormat.format(DateTime.now())}",
|
||||
validator: FormBuilderValidators.required(),
|
||||
decoration: InputDecoration(
|
||||
labelText: S.of(context).documentTitlePropertyLabel,
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () {
|
||||
_formKey.currentState?.fields[DocumentModel.titleKey]?.didChange("");
|
||||
_formKey.currentState?.fields[fkFileName]?.didChange(".pdf");
|
||||
},
|
||||
),
|
||||
errorText: _errors[DocumentModel.titleKey],
|
||||
),
|
||||
onChanged: (value) {
|
||||
final String? transformedValue = value?.replaceAll(RegExp(r"[\W_]"), "_");
|
||||
_formKey.currentState?.fields[fkFileName]
|
||||
?.didChange("${transformedValue ?? ''}.pdf");
|
||||
},
|
||||
),
|
||||
FormBuilderTextField(
|
||||
autovalidateMode: AutovalidateMode.always,
|
||||
readOnly: true,
|
||||
enabled: false,
|
||||
name: fkFileName,
|
||||
decoration: InputDecoration(
|
||||
labelText: S.of(context).documentUploadFileNameLabel,
|
||||
),
|
||||
initialValue: "scan_${fileNameDateFormat.format(DateTime.now())}.pdf",
|
||||
),
|
||||
FormBuilderDateTimePicker(
|
||||
autovalidateMode: AutovalidateMode.always,
|
||||
format: DateFormat("dd. MMMM yyyy"), //TODO: INTL
|
||||
inputType: InputType.date,
|
||||
name: DocumentModel.createdKey,
|
||||
initialValue: null,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.calendar_month_outlined),
|
||||
labelText: S.of(context).documentCreatedPropertyLabel + " *",
|
||||
),
|
||||
),
|
||||
BlocBuilder<DocumentTypeCubit, Map<int, DocumentType>>(
|
||||
bloc: getIt<DocumentTypeCubit>(), //TODO: Use provider
|
||||
builder: (context, state) {
|
||||
return LabelFormField<DocumentType, DocumentTypeQuery>(
|
||||
notAssignedSelectable: false,
|
||||
formBuilderState: _formKey.currentState,
|
||||
labelCreationWidgetBuilder: (initialValue) => BlocProvider.value(
|
||||
value: BlocProvider.of<DocumentTypeCubit>(context),
|
||||
child: AddDocumentTypePage(initialName: initialValue),
|
||||
),
|
||||
label: S.of(context).documentDocumentTypePropertyLabel + " *",
|
||||
name: DocumentModel.documentTypeKey,
|
||||
state: state,
|
||||
queryParameterIdBuilder: DocumentTypeQuery.fromId,
|
||||
queryParameterNotAssignedBuilder: DocumentTypeQuery.notAssigned,
|
||||
prefixIcon: const Icon(Icons.description_outlined),
|
||||
);
|
||||
},
|
||||
),
|
||||
BlocBuilder<CorrespondentCubit, Map<int, Correspondent>>(
|
||||
bloc: getIt<CorrespondentCubit>(), //TODO: Use provider
|
||||
builder: (context, state) {
|
||||
return LabelFormField<Correspondent, CorrespondentQuery>(
|
||||
notAssignedSelectable: false,
|
||||
formBuilderState: _formKey.currentState,
|
||||
labelCreationWidgetBuilder: (initialValue) => BlocProvider.value(
|
||||
value: BlocProvider.of<CorrespondentCubit>(context),
|
||||
child: AddCorrespondentPage(initalValue: initialValue),
|
||||
),
|
||||
label: S.of(context).documentCorrespondentPropertyLabel + " *",
|
||||
name: DocumentModel.correspondentKey,
|
||||
state: state,
|
||||
queryParameterIdBuilder: CorrespondentQuery.fromId,
|
||||
queryParameterNotAssignedBuilder: CorrespondentQuery.notAssigned,
|
||||
prefixIcon: const Icon(Icons.person_outline),
|
||||
);
|
||||
},
|
||||
),
|
||||
const TagFormField(
|
||||
name: DocumentModel.tagsKey,
|
||||
//Label: "Tags" + " *",
|
||||
),
|
||||
Text(
|
||||
"* " + S.of(context).uploadPageAutomaticallInferredFieldsHintText,
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
),
|
||||
].padded(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onSubmit() async {
|
||||
_formKey.currentState?.save();
|
||||
if (_formKey.currentState?.validate() ?? false) {
|
||||
try {
|
||||
setState(() {
|
||||
_isUploadLoading = true;
|
||||
});
|
||||
await BlocProvider.of<DocumentsCubit>(context).addDocument(
|
||||
widget.pdfBytes,
|
||||
_formKey.currentState?.value[fkFileName],
|
||||
onConsumptionFinished: (document) {
|
||||
ScaffoldMessenger.of(rootScaffoldKey.currentContext!).showSnackBar(
|
||||
SnackBar(
|
||||
action: SnackBarAction(
|
||||
onPressed: () {
|
||||
getIt<DocumentsCubit>().reloadDocuments();
|
||||
},
|
||||
label: S.of(context).documentUploadProcessingSuccessfulReloadActionText,
|
||||
),
|
||||
content: Text(S.of(context).documentUploadProcessingSuccessfulText),
|
||||
),
|
||||
);
|
||||
},
|
||||
title: _formKey.currentState?.value[DocumentModel.titleKey],
|
||||
documentType:
|
||||
(_formKey.currentState?.value[DocumentModel.documentTypeKey] as IdQueryParameter).id,
|
||||
correspondent:
|
||||
(_formKey.currentState?.value[DocumentModel.correspondentKey] as IdQueryParameter).id,
|
||||
tags: (_formKey.currentState?.value[DocumentModel.tagsKey] as IdsQueryParameter).ids,
|
||||
createdAt: (_formKey.currentState?.value[DocumentModel.createdKey] as DateTime?),
|
||||
);
|
||||
setState(() {
|
||||
_isUploadLoading = false;
|
||||
});
|
||||
getIt<DocumentScannerCubit>().reset();
|
||||
Navigator.pop(context);
|
||||
showSnackBar(context, S.of(context).documentUploadSuccessText);
|
||||
} on ErrorMessage catch (error) {
|
||||
showError(context, error);
|
||||
} on Map<String, String> catch (errorMessages) {
|
||||
setState(() => _errors = errorMessages);
|
||||
} catch (other) {
|
||||
showSnackBar(context, other.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isUploadLoading = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
184
lib/features/scan/view/scanner_page.dart
Normal file
184
lib/features/scan/view/scanner_page.dart
Normal file
@@ -0,0 +1,184 @@
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:edge_detection/edge_detection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_paperless_mobile/core/bloc/label_bloc_provider.dart';
|
||||
import 'package:flutter_paperless_mobile/di_initializer.dart';
|
||||
import 'package:flutter_paperless_mobile/features/documents/bloc/documents_cubit.dart';
|
||||
import 'package:flutter_paperless_mobile/features/home/view/widget/info_drawer.dart';
|
||||
import 'package:flutter_paperless_mobile/features/scan/bloc/document_scanner_cubit.dart';
|
||||
import 'package:flutter_paperless_mobile/features/scan/view/document_upload_page.dart';
|
||||
import 'package:flutter_paperless_mobile/features/scan/view/widgets/grid_image_item_widget.dart';
|
||||
import 'package:flutter_paperless_mobile/generated/l10n.dart';
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart' as pw;
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class ScannerPage extends StatefulWidget {
|
||||
const ScannerPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ScannerPage> createState() => _ScannerPageState();
|
||||
}
|
||||
|
||||
class _ScannerPageState extends State<ScannerPage> with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _fabPulsingController;
|
||||
late final Animation _animation;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_fabPulsingController = AnimationController(vsync: this, duration: const Duration(seconds: 1))
|
||||
..repeat(reverse: true);
|
||||
_animation = Tween(begin: 1.0, end: 1.2).animate(_fabPulsingController)
|
||||
..addListener(() {
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_fabPulsingController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
drawer: const InfoDrawer(),
|
||||
floatingActionButton: BlocBuilder<DocumentScannerCubit, List<File>>(
|
||||
builder: (context, state) {
|
||||
final fab = FloatingActionButton(
|
||||
onPressed: () => _openDocumentScanner(context),
|
||||
child: const Icon(Icons.add_a_photo_outlined),
|
||||
);
|
||||
if (state.isEmpty) {
|
||||
return Transform.scale(
|
||||
child: fab,
|
||||
scale: _animation.value,
|
||||
);
|
||||
}
|
||||
return fab;
|
||||
},
|
||||
),
|
||||
appBar: _buildAppBar(context),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: _buildBody(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
AppBar _buildAppBar(BuildContext context) {
|
||||
return AppBar(
|
||||
title: Text(S.of(context).documentScannerPageTitle),
|
||||
actions: [
|
||||
BlocBuilder<DocumentScannerCubit, List<File>>(
|
||||
builder: (context, state) {
|
||||
return IconButton(
|
||||
onPressed: state.isEmpty ? null : () => _reset(context),
|
||||
icon: const Icon(Icons.delete_sweep),
|
||||
tooltip: S.of(context).documentScannerPageResetButtonTooltipText,
|
||||
);
|
||||
},
|
||||
),
|
||||
BlocBuilder<DocumentScannerCubit, List<File>>(
|
||||
builder: (context, state) {
|
||||
return IconButton(
|
||||
onPressed: state.isEmpty ? null : () => _export(context),
|
||||
icon: const Icon(Icons.done),
|
||||
tooltip: S.of(context).documentScannerPageUploadButtonTooltip,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _openDocumentScanner(BuildContext context) async {
|
||||
await _requestCameraPermissions();
|
||||
final imagePath = await EdgeDetection.detectEdge;
|
||||
if (imagePath == null) {
|
||||
return;
|
||||
}
|
||||
final file = File(imagePath);
|
||||
BlocProvider.of<DocumentScannerCubit>(context).addScan(file);
|
||||
}
|
||||
|
||||
void _export(BuildContext context) async {
|
||||
final pw.Document doc = pw.Document();
|
||||
|
||||
for (var element in BlocProvider.of<DocumentScannerCubit>(context).state) {
|
||||
final img = pw.MemoryImage(element.readAsBytesSync());
|
||||
doc.addPage(
|
||||
pw.Page(
|
||||
pageFormat: PdfPageFormat(img.width!.toDouble(), img.height!.toDouble()),
|
||||
build: (context) => pw.Image(img),
|
||||
),
|
||||
);
|
||||
}
|
||||
final bytes = await doc.save();
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BlocProvider.value(
|
||||
value: getIt<DocumentsCubit>(),
|
||||
child: LabelBlocProvider(
|
||||
child: DocumentUploadPage(
|
||||
pdfBytes: bytes,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody() {
|
||||
return BlocBuilder<DocumentScannerCubit, List<File>>(
|
||||
builder: (context, scans) {
|
||||
if (scans.isNotEmpty) {
|
||||
return _buildImageGrid(scans);
|
||||
}
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
S.of(context).documentScannerPageEmptyStateText,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildImageGrid(List<File> scans) {
|
||||
return GridView.builder(
|
||||
itemCount: scans.length,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 1 / sqrt(2),
|
||||
crossAxisSpacing: 10,
|
||||
mainAxisSpacing: 10,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
return GridImageItemWidget(
|
||||
file: scans[index],
|
||||
onDelete: () => BlocProvider.of<DocumentScannerCubit>(context).removeScan(index),
|
||||
index: index,
|
||||
totalNumberOfFiles: scans.length,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void _reset(BuildContext context) {
|
||||
BlocProvider.of<DocumentScannerCubit>(context).reset();
|
||||
}
|
||||
|
||||
Future<void> _requestCameraPermissions() async {
|
||||
final hasPermission = await Permission.camera.isGranted;
|
||||
if (!hasPermission) {
|
||||
Permission.camera.request();
|
||||
}
|
||||
}
|
||||
}
|
||||
106
lib/features/scan/view/widgets/grid_image_item_widget.dart
Normal file
106
lib/features/scan/view/widgets/grid_image_item_widget.dart
Normal file
@@ -0,0 +1,106 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:photo_view/photo_view.dart';
|
||||
|
||||
typedef DeleteCallback = void Function();
|
||||
typedef OnImageOperation = void Function(File);
|
||||
|
||||
class GridImageItemWidget extends StatefulWidget {
|
||||
final File file;
|
||||
final DeleteCallback onDelete;
|
||||
//final OnImageOperation onImageOperation;
|
||||
|
||||
final int index;
|
||||
final int totalNumberOfFiles;
|
||||
|
||||
const GridImageItemWidget({
|
||||
Key? key,
|
||||
required this.file,
|
||||
required this.onDelete,
|
||||
required this.index,
|
||||
required this.totalNumberOfFiles,
|
||||
//required this.onImageOperation,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<GridImageItemWidget> createState() => _GridImageItemWidgetState();
|
||||
}
|
||||
|
||||
class _GridImageItemWidgetState extends State<GridImageItemWidget> {
|
||||
bool isProcessing = false;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () => _showImage(context),
|
||||
child: _buildImageItem(context),
|
||||
);
|
||||
}
|
||||
|
||||
Card _buildImageItem(BuildContext context) {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8.0),
|
||||
child: Stack(
|
||||
children: [
|
||||
Align(alignment: Alignment.bottomCenter, child: _buildNumbering()),
|
||||
Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: IconButton(
|
||||
onPressed: widget.onDelete,
|
||||
icon: const Icon(Icons.close),
|
||||
),
|
||||
),
|
||||
isProcessing
|
||||
? _buildIsProcessing()
|
||||
: Align(
|
||||
alignment: Alignment.center,
|
||||
child: AspectRatio(
|
||||
aspectRatio: 4 / 3,
|
||||
child: Image.file(
|
||||
widget.file,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Center _buildIsProcessing() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: const [
|
||||
CircularProgressIndicator(),
|
||||
Text(
|
||||
"Processing transformation...",
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showImage(BuildContext context) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => Scaffold(
|
||||
appBar: AppBar(
|
||||
title: _buildNumbering(prefix: "Image"),
|
||||
),
|
||||
body: PhotoView(imageProvider: FileImage(widget.file)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNumbering({String? prefix}) {
|
||||
return Text(
|
||||
"${prefix ?? ""} ${widget.index + 1}/${widget.totalNumberOfFiles}",
|
||||
);
|
||||
}
|
||||
}
|
||||
41
lib/features/scan/view/widgets/scanner.dart
Normal file
41
lib/features/scan/view/widgets/scanner.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
typedef OnImageScannedCallback = void Function(File);
|
||||
|
||||
class ScannerWidget extends StatefulWidget {
|
||||
final OnImageScannedCallback onImageScannedCallback;
|
||||
const ScannerWidget({
|
||||
Key? key,
|
||||
required this.onImageScannedCallback,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ScannerWidgetState createState() => _ScannerWidgetState();
|
||||
}
|
||||
|
||||
class _ScannerWidgetState extends State<ScannerWidget> {
|
||||
List<File> documents = List.empty(growable: true);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text("Scan document")),
|
||||
body: FutureBuilder<PermissionStatus>(
|
||||
future: Permission.camera.request(),
|
||||
builder: (BuildContext context, AsyncSnapshot<PermissionStatus> snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (snapshot.data!.isGranted) {
|
||||
return Container();
|
||||
}
|
||||
return const Center(
|
||||
child: Text("No camera permissions, please enable in settings!"),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
64
lib/features/scan/view/widgets/upload_dialog.dart
Normal file
64
lib/features/scan/view/widgets/upload_dialog.dart
Normal file
@@ -0,0 +1,64 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class UploadDialog extends StatefulWidget {
|
||||
const UploadDialog({
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<UploadDialog> createState() => _UploadDialogState();
|
||||
}
|
||||
|
||||
class _UploadDialogState extends State<UploadDialog> {
|
||||
late TextEditingController _controller;
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
final DateFormat format = DateFormat("yyyy_MM_dd_hh_mm_ss");
|
||||
final today = format.format(DateTime.now());
|
||||
_controller = TextEditingController.fromValue(TextEditingValue(text: "Scan_$today.pdf"));
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text("Upload to paperless-ng"),
|
||||
content: Form(
|
||||
key: _formKey,
|
||||
child: TextFormField(
|
||||
controller: _controller,
|
||||
validator: (text) {
|
||||
if (text == null || text.isEmpty) {
|
||||
return "Filename must be specified!";
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text("Cancel"),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
if (!_formKey.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
var txt = _controller.text;
|
||||
if (!txt.endsWith(".pdf")) {
|
||||
txt += ".pdf";
|
||||
}
|
||||
Navigator.of(context).pop(txt);
|
||||
},
|
||||
child: const Text("Upload"),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user