2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-13 10:45:29 +00:00

Refactor part image upload and part attachment upload

This commit is contained in:
Oliver
2021-08-16 17:55:14 +10:00
parent 7317f9cbad
commit 3f63f1e8a7
2 changed files with 25 additions and 97 deletions

View File

@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:image_picker/image_picker.dart';
import 'package:inventree/inventree/part.dart';
import 'package:inventree/widget/fields.dart';
import 'package:inventree/widget/refreshable_state.dart';
import 'package:inventree/widget/snacks.dart';
@ -46,16 +47,14 @@ class _PartAttachmentDisplayState extends RefreshableState<PartAttachmentsWidget
// File upload
actions.add(
IconButton(
icon: FaIcon(FontAwesomeIcons.fileUpload),
onPressed: uploadFile,
)
);
// Upload from camera
actions.add(
IconButton(
icon: FaIcon(FontAwesomeIcons.camera),
onPressed: uploadFromCamera,
icon: FaIcon(FontAwesomeIcons.plusCircle),
onPressed: () async {
FilePickerDialog.pickFile(
onPicked: (File file) {
upload(file);
}
);
},
)
);
}
@ -77,45 +76,6 @@ class _PartAttachmentDisplayState extends RefreshableState<PartAttachmentsWidget
showSnackIcon(L10().uploadFailed, success: false);
}
refresh();
}
/*
* Select a file from the device to upload
*/
Future<void> uploadFile() async {
final FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) {
String? path = result.files.single.path;
if (path != null) {
File attachment = File(path);
upload(attachment);
}
}
}
/*
* Upload an attachment by taking a new picture with the built in device camera
*/
Future<void> uploadFromCamera() async {
final picker = ImagePicker();
final pickedImage = await picker.getImage(source: ImageSource.camera);
if (pickedImage != null) {
File? attachment = File(pickedImage.path);
upload(attachment);
}
refresh();
}