2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-07-30 01:01:37 +00:00

Update package versions and refactor accordingly

This commit is contained in:
Oliver
2021-06-18 21:28:07 +10:00
parent a415a2cd99
commit 65cabc2fa9
12 changed files with 205 additions and 144 deletions

View File

@@ -1,7 +1,7 @@
import 'package:InvenTree/app_settings.dart';
import 'package:InvenTree/widget/snacks.dart';
import 'package:audioplayers/audio_cache.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
@@ -64,7 +64,7 @@ Future<void> showInfoDialog(BuildContext context, String title, String descripti
showDialog(
context: context,
child: SimpleDialog(
builder: (BuildContext context) => SimpleDialog(
title: ListTile(
title: Text(info),
leading: FaIcon(icon),
@@ -119,7 +119,7 @@ Future<void> showServerError(String title, String description) async {
final bool tones = await InvenTreeSettingsManager().getValue("serverSounds", true) as bool;
if (tones) {
AudioCache player = AudioCache();
final player = AudioCache();
player.play("sounds/server_error.mp3");
}

View File

@@ -28,24 +28,28 @@ class ImagePickerField extends FormField<File> {
}
static Future<void> _getImageFromGallery(FormFieldState<File> field) async {
File image;
await ImagePicker.pickImage(source: ImageSource.gallery).then((File img) {
image = img;
});
field.didChange(image);
final picker = ImagePicker();
final pickedImage = await picker.getImage(source: ImageSource.gallery);
if (pickedImage != null)
{
field.didChange(File(pickedImage.path));
}
}
static Future<void> _getImageFromCamera(FormFieldState<File> field) async {
File image;
await ImagePicker.pickImage(source: ImageSource.camera).then((File img) {
image = img;
});
final picker = ImagePicker();
final pickedImage = await picker.getImage(source: ImageSource.camera);
if (pickedImage != null)
{
field.didChange(File(pickedImage.path));
}
field.didChange(image);
}
ImagePickerField(BuildContext context, {String label = "Attach Image", Function onSaved, bool required = false}) :

View File

@@ -34,6 +34,7 @@ class PartDetailWidget extends StatefulWidget {
class _PartDisplayState extends RefreshableState<PartDetailWidget> {
final _editImageKey = GlobalKey<FormState>();
final _editPartKey = GlobalKey<FormState>();
@override
@@ -116,6 +117,39 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
refresh();
}
void _uploadImage(File image) async {
print("Uploading image...");
await part.uploadImage(image);
print("Done");
refresh();
}
void _selectImage() {
File _attachment;
if (!InvenTreeAPI().checkPermission('part', 'change')) {
return;
}
showFormDialog(L10().selectImage,
key: _editImageKey,
callback: () {
_uploadImage(_attachment);
},
fields: <Widget>[
ImagePickerField(
context,
label: L10().attachImage,
required: true,
onSaved: (attachment) => _attachment = attachment,
),
]
);
}
void _editPartDialog() {
// Values which can be edited
@@ -189,6 +223,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
MaterialPageRoute(builder: (context) => FullScreenWidget(part.fullname, part.image))
);
}),
onLongPress: _selectImage,
),
);
}