mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-12 18:25:26 +00:00
Add ability to edit Part object
This commit is contained in:
@ -3,12 +3,13 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class QuantityField extends TextFormField {
|
||||
|
||||
QuantityField({String label = "", String hint = "", double max = null, TextEditingController controller}) :
|
||||
QuantityField({String label = "", String hint = "", String initial = "", double max = null, TextEditingController controller}) :
|
||||
super(
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
hintText: hint,
|
||||
),
|
||||
initialValue: initial,
|
||||
controller: controller,
|
||||
keyboardType: TextInputType.numberWithOptions(signed: false, decimal: true),
|
||||
validator: (value) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
import 'package:InvenTree/inventree/part.dart';
|
||||
import 'package:InvenTree/widget/category_display.dart';
|
||||
import 'package:InvenTree/widget/dialogs.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -24,6 +25,8 @@ class PartDetailWidget extends StatefulWidget {
|
||||
|
||||
class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
|
||||
final _editPartKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
String getAppBarTitle(BuildContext context) { return "Part"; }
|
||||
|
||||
@ -40,6 +43,85 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
await part.reload(context);
|
||||
}
|
||||
|
||||
void _savePart(Map<String, String> values) async {
|
||||
|
||||
Navigator.of(context).pop();
|
||||
|
||||
var response = await part.update(context, values: values);
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
void _editPartDialog() {
|
||||
|
||||
// Values which can be edited
|
||||
var _name;
|
||||
var _description;
|
||||
var _ipn;
|
||||
var _revision;
|
||||
|
||||
showFormDialog(context, "Edit Part",
|
||||
key: _editPartKey,
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
child: Text("Cancel"),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
FlatButton(
|
||||
child: Text("Save"),
|
||||
onPressed: () {
|
||||
if (_editPartKey.currentState.validate()) {
|
||||
_editPartKey.currentState.save();
|
||||
|
||||
_savePart({
|
||||
"name": _name,
|
||||
"description": _description,
|
||||
"IPN": _ipn,
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
fields: <Widget>[
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Part Name",
|
||||
hintText: "Enter part name",
|
||||
),
|
||||
initialValue: part.name,
|
||||
validator: (value) {
|
||||
if (value.isEmpty) return "Name cannot be empty";
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) => _name = value,
|
||||
),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Part Description",
|
||||
hintText: "Enter part description",
|
||||
),
|
||||
initialValue: part.description,
|
||||
validator: (value) {
|
||||
if (value.isEmpty) return "Description cannot be empty";
|
||||
return null;
|
||||
},
|
||||
onSaved: (value) => _description = value,
|
||||
),
|
||||
TextFormField(
|
||||
decoration: InputDecoration(
|
||||
labelText: "Internal Part Number",
|
||||
hintText: "Enter internal part number",
|
||||
),
|
||||
initialValue: part.IPN,
|
||||
onSaved: (value) => _ipn = value,
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Build a list of tiles to display under the part description
|
||||
*/
|
||||
@ -58,7 +140,7 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: FaIcon(FontAwesomeIcons.edit),
|
||||
onPressed: null,
|
||||
onPressed: _editPartDialog,
|
||||
),
|
||||
)
|
||||
)
|
||||
|
Reference in New Issue
Block a user