CSV import
This commit is contained in:
parent
17481eada2
commit
1e982d78d3
|
|
@ -1,5 +1,9 @@
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:image_picker/image_picker.dart';
|
||||||
import 'package:invoiceninja_flutter/constants.dart';
|
import 'package:invoiceninja_flutter/constants.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/entities.dart';
|
import 'package:invoiceninja_flutter/data/models/entities.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/form_card.dart';
|
import 'package:invoiceninja_flutter/ui/app/form_card.dart';
|
||||||
|
|
@ -8,6 +12,9 @@ import 'package:invoiceninja_flutter/ui/app/forms/decorated_form_field.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/settings/import_export_vm.dart';
|
import 'package:invoiceninja_flutter/ui/settings/import_export_vm.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
||||||
|
import 'package:invoiceninja_flutter/utils/web_stub.dart'
|
||||||
|
if (dart.library.html) 'package:invoiceninja_flutter/utils/web.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
class ImportExport extends StatefulWidget {
|
class ImportExport extends StatefulWidget {
|
||||||
const ImportExport({
|
const ImportExport({
|
||||||
|
|
@ -27,6 +34,8 @@ class _ImportExportState extends State<ImportExport> {
|
||||||
FocusScopeNode _focusNode;
|
FocusScopeNode _focusNode;
|
||||||
bool autoValidate = false;
|
bool autoValidate = false;
|
||||||
String _filePath;
|
String _filePath;
|
||||||
|
String _fileName;
|
||||||
|
Uint8List _fileBytes;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
@ -82,9 +91,10 @@ class _ImportExportState extends State<ImportExport> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
DecoratedFormField(
|
DecoratedFormField(
|
||||||
|
key: ValueKey(_fileName),
|
||||||
enabled: false,
|
enabled: false,
|
||||||
label: localization.csvFile,
|
label: localization.csvFile,
|
||||||
initialValue: localization.noFileSelected,
|
initialValue: _fileName ?? localization.noFileSelected,
|
||||||
),
|
),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
Row(
|
Row(
|
||||||
|
|
@ -94,7 +104,20 @@ class _ImportExportState extends State<ImportExport> {
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(5)),
|
borderRadius: BorderRadius.circular(5)),
|
||||||
child: Text(localization.selectFile),
|
child: Text(localization.selectFile),
|
||||||
onPressed: () {},
|
onPressed: () async {
|
||||||
|
final result = await FilePicker.platform.pickFiles(
|
||||||
|
type: FileType.custom,
|
||||||
|
allowedExtensions: ['csv'],
|
||||||
|
);
|
||||||
|
if (result != null) {
|
||||||
|
setState(() {
|
||||||
|
final file = result.files.single;
|
||||||
|
_filePath = file.path;
|
||||||
|
_fileName = file.name;
|
||||||
|
_fileBytes = file.bytes;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(width: kTableColumnGap),
|
SizedBox(width: kTableColumnGap),
|
||||||
|
|
@ -103,9 +126,11 @@ class _ImportExportState extends State<ImportExport> {
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(5)),
|
borderRadius: BorderRadius.circular(5)),
|
||||||
child: Text(localization.uploadFile),
|
child: Text(localization.uploadFile),
|
||||||
onPressed: _filePath == null ? null : () {
|
onPressed: _fileName == null
|
||||||
//
|
? null
|
||||||
},
|
: () {
|
||||||
|
//
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -281,6 +281,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.0.0-nullsafety.4"
|
version: "6.0.0-nullsafety.4"
|
||||||
|
file_picker:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: file_picker
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.1"
|
||||||
firebase:
|
firebase:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ dependencies:
|
||||||
permission_handler: ^5.0.1+1
|
permission_handler: ^5.0.1+1
|
||||||
contacts_service: ^0.4.6
|
contacts_service: ^0.4.6
|
||||||
extended_image: 1.3.1-dev #TODO remove
|
extended_image: 1.3.1-dev #TODO remove
|
||||||
|
file_picker: ^2.1.1
|
||||||
|
|
||||||
dependency_overrides:
|
dependency_overrides:
|
||||||
# https://github.com/flutter/flutter/issues/70433#issuecomment-727154345
|
# https://github.com/flutter/flutter/issues/70433#issuecomment-727154345
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue