mirror of
https://github.com/inventree/inventree-app.git
synced 2025-05-13 20:43:11 +00:00
Upload part attachnents
- Select file from device - Take picture with camera
This commit is contained in:
parent
d9d52613b6
commit
a5edb84723
@ -1,18 +0,0 @@
|
|||||||
#
|
|
||||||
# NOTE: This podspec is NOT to be published. It is only used as a local source!
|
|
||||||
# This is a generated file; do not edit or check into version control.
|
|
||||||
#
|
|
||||||
|
|
||||||
Pod::Spec.new do |s|
|
|
||||||
s.name = 'Flutter'
|
|
||||||
s.version = '1.0.0'
|
|
||||||
s.summary = 'High-performance, high-fidelity mobile apps.'
|
|
||||||
s.homepage = 'https://flutter.io'
|
|
||||||
s.license = { :type => 'MIT' }
|
|
||||||
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
|
|
||||||
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
|
|
||||||
s.ios.deployment_target = '8.0'
|
|
||||||
# Framework linking is handled by Flutter tooling, not CocoaPods.
|
|
||||||
# Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs.
|
|
||||||
s.vendored_frameworks = 'path/to/nothing'
|
|
||||||
end
|
|
@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:inventree/api.dart';
|
import 'package:inventree/api.dart';
|
||||||
@ -8,6 +9,7 @@ import 'package:inventree/widget/dialogs.dart';
|
|||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
import '../l10.dart';
|
import '../l10.dart';
|
||||||
import '../api_form.dart';
|
import '../api_form.dart';
|
||||||
@ -506,6 +508,24 @@ class InvenTreeAttachment extends InvenTreeModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
InvenTreeAttachment.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
InvenTreeAttachment.fromJson(Map<String, dynamic> json) : super.fromJson(json);
|
||||||
|
|
||||||
|
Future<bool> uploadAttachment(File attachment, {String comment = "", Map<String, String> fields = const {}}) async {
|
||||||
|
|
||||||
|
final http.StreamedResponse response = await InvenTreeAPI().uploadFile(
|
||||||
|
URL,
|
||||||
|
attachment,
|
||||||
|
method: 'POST',
|
||||||
|
name: 'attachment',
|
||||||
|
fields: fields
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
2
lib/l10n
2
lib/l10n
@ -1 +1 @@
|
|||||||
Subproject commit 20dce387ab4088e22b67c6ffd1fb50b6a1f252e8
|
Subproject commit faec97124b652ca219d6c0899dd0234cf42e4fa7
|
@ -1,10 +1,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.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/inventree/part.dart';
|
||||||
import 'package:inventree/widget/refreshable_state.dart';
|
import 'package:inventree/widget/refreshable_state.dart';
|
||||||
|
import 'package:inventree/widget/snacks.dart';
|
||||||
|
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import '../api.dart';
|
import '../api.dart';
|
||||||
import '../l10.dart';
|
import '../l10.dart';
|
||||||
@ -36,11 +41,21 @@ class _PartAttachmentDisplayState extends RefreshableState<PartAttachmentsWidget
|
|||||||
|
|
||||||
List<Widget> actions = [];
|
List<Widget> actions = [];
|
||||||
|
|
||||||
if (false && InvenTreeAPI().checkPermission('part', 'change')) {
|
if (InvenTreeAPI().checkPermission('part', 'change')) {
|
||||||
|
|
||||||
|
// File upload
|
||||||
actions.add(
|
actions.add(
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: FaIcon(FontAwesomeIcons.plus),
|
icon: FaIcon(FontAwesomeIcons.fileUpload),
|
||||||
onPressed: null,
|
onPressed: uploadFile,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Upload from camera
|
||||||
|
actions.add(
|
||||||
|
IconButton(
|
||||||
|
icon: FaIcon(FontAwesomeIcons.camera),
|
||||||
|
onPressed: uploadFromCamera,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -48,6 +63,62 @@ class _PartAttachmentDisplayState extends RefreshableState<PartAttachmentsWidget
|
|||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> upload(File file) async {
|
||||||
|
final bool result = await InvenTreePartAttachment().uploadAttachment(
|
||||||
|
file,
|
||||||
|
fields: {
|
||||||
|
"part": "${part.pk}"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
showSnackIcon(L10().uploadSuccess, success: true);
|
||||||
|
} else {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> request() async {
|
Future<void> request() async {
|
||||||
|
|
||||||
|
13
pubspec.lock
13
pubspec.lock
@ -183,6 +183,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.1.2"
|
version: "6.1.2"
|
||||||
|
file_picker:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: file_picker
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "4.0.0"
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
@ -279,21 +286,21 @@ packages:
|
|||||||
name: image_picker
|
name: image_picker
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.8.0+3"
|
version: "0.8.3+2"
|
||||||
image_picker_for_web:
|
image_picker_for_web:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: image_picker_for_web
|
name: image_picker_for_web
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.0"
|
version: "2.1.2"
|
||||||
image_picker_platform_interface:
|
image_picker_platform_interface:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: image_picker_platform_interface
|
name: image_picker_platform_interface
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
version: "2.2.0"
|
||||||
infinite_scroll_pagination:
|
infinite_scroll_pagination:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -30,7 +30,8 @@ dependencies:
|
|||||||
font_awesome_flutter: ^9.1.0 # FontAwesome icon set
|
font_awesome_flutter: ^9.1.0 # FontAwesome icon set
|
||||||
flutter_speed_dial: ^3.0.5 # FAB menu elements
|
flutter_speed_dial: ^3.0.5 # FAB menu elements
|
||||||
sentry_flutter: 5.0.0 # Error reporting
|
sentry_flutter: 5.0.0 # Error reporting
|
||||||
image_picker: ^0.8.0 # Select or take photos
|
image_picker: ^0.8.3 # Select or take photos
|
||||||
|
file_picker: ^4.0.0 # Select files from the device
|
||||||
url_launcher: 6.0.9 # Open link in system browser
|
url_launcher: 6.0.9 # Open link in system browser
|
||||||
flutter_markdown: ^0.6.2 # Rendering markdown
|
flutter_markdown: ^0.6.2 # Rendering markdown
|
||||||
camera: # Camera
|
camera: # Camera
|
||||||
|
Loading…
x
Reference in New Issue
Block a user