mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-29 05:56:47 +00:00
Improve form for "AddTestResult"
This commit is contained in:
parent
c13a4d40f0
commit
5280e247f4
@ -22,7 +22,7 @@ class CheckBoxField extends FormField<bool> {
|
|||||||
|
|
||||||
class StringField extends TextFormField {
|
class StringField extends TextFormField {
|
||||||
|
|
||||||
StringField({String label, String hint, String initial, Function onSaved, Function validator, bool allowEmpty = false}) :
|
StringField({String label, String hint, String initial, Function onSaved, Function validator, bool allowEmpty = false, bool isEnabled = true}) :
|
||||||
super(
|
super(
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: label,
|
labelText: label,
|
||||||
@ -30,8 +30,8 @@ class StringField extends TextFormField {
|
|||||||
),
|
),
|
||||||
initialValue: initial,
|
initialValue: initial,
|
||||||
onSaved: onSaved,
|
onSaved: onSaved,
|
||||||
|
enabled: isEnabled,
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
print("Value: ${value}");
|
|
||||||
if (!allowEmpty && value.isEmpty) {
|
if (!allowEmpty && value.isEmpty) {
|
||||||
return "Value cannot be empty";
|
return "Value cannot be empty";
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ import 'package:InvenTree/inventree/part.dart';
|
|||||||
import 'package:InvenTree/inventree/stock.dart';
|
import 'package:InvenTree/inventree/stock.dart';
|
||||||
import 'package:InvenTree/inventree/model.dart';
|
import 'package:InvenTree/inventree/model.dart';
|
||||||
import 'package:InvenTree/api.dart';
|
import 'package:InvenTree/api.dart';
|
||||||
|
import 'package:InvenTree/widget/dialogs.dart';
|
||||||
|
import 'package:InvenTree/widget/fields.dart';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -22,6 +24,8 @@ class StockItemTestResultsWidget extends StatefulWidget {
|
|||||||
|
|
||||||
class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestResultsWidget> {
|
class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestResultsWidget> {
|
||||||
|
|
||||||
|
final _addResultKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getAppBarTitle(BuildContext context) { return "Test Results"; }
|
String getAppBarTitle(BuildContext context) { return "Test Results"; }
|
||||||
|
|
||||||
@ -35,6 +39,57 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
|
|
||||||
_StockItemTestResultDisplayState(this.item);
|
_StockItemTestResultDisplayState(this.item);
|
||||||
|
|
||||||
|
void addTestResult({String name = '', bool nameIsEditable = true, bool result = false, String value = '', bool valueRequired = false, bool attachmentRequired = false}) {
|
||||||
|
|
||||||
|
showFormDialog(context, "Add Test Data",
|
||||||
|
key: _addResultKey,
|
||||||
|
actions: <Widget>[
|
||||||
|
FlatButton(
|
||||||
|
child: Text("Cancel"),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
FlatButton(
|
||||||
|
child: Text("Save"),
|
||||||
|
onPressed: () {
|
||||||
|
if (_addResultKey.currentState.validate()) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
fields: <Widget>[
|
||||||
|
StringField(
|
||||||
|
label: "Test Name",
|
||||||
|
initial: name,
|
||||||
|
isEnabled: nameIsEditable,
|
||||||
|
),
|
||||||
|
CheckBoxField(
|
||||||
|
label: "Result",
|
||||||
|
hint: "Test passed or failed",
|
||||||
|
initial: true,
|
||||||
|
),
|
||||||
|
StringField(
|
||||||
|
label: "Value",
|
||||||
|
initial: value,
|
||||||
|
allowEmpty: true,
|
||||||
|
validator: (String value) {
|
||||||
|
print("Value: " + value);
|
||||||
|
if (valueRequired && (value == null || value.isEmpty)) {
|
||||||
|
return "Value required for this test";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
StringField(
|
||||||
|
allowEmpty: true,
|
||||||
|
label: "Notes",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Squish together templates and results
|
// Squish together templates and results
|
||||||
List<InvenTreeModel> getTestResults() {
|
List<InvenTreeModel> getTestResults() {
|
||||||
var templates = item.testTemplates;
|
var templates = item.testTemplates;
|
||||||
@ -117,6 +172,14 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
),
|
),
|
||||||
subtitle: Text(subtitle),
|
subtitle: Text(subtitle),
|
||||||
trailing: icon,
|
trailing: icon,
|
||||||
|
onLongPress: () {
|
||||||
|
addTestResult(
|
||||||
|
name: template.testName,
|
||||||
|
nameIsEditable: false,
|
||||||
|
valueRequired: template.requiresValue,
|
||||||
|
attachmentRequired: template.requiresAttachment,
|
||||||
|
);
|
||||||
|
}
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,6 +202,14 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
title: Text("${result.testName}"),
|
title: Text("${result.testName}"),
|
||||||
subtitle: Text("${result.value}"),
|
subtitle: Text("${result.value}"),
|
||||||
trailing: icon,
|
trailing: icon,
|
||||||
|
onLongPress: () {
|
||||||
|
addTestResult(
|
||||||
|
name: result.testName,
|
||||||
|
nameIsEditable: false,
|
||||||
|
valueRequired: false,
|
||||||
|
attachmentRequired: false
|
||||||
|
);
|
||||||
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -167,7 +238,9 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
|
|||||||
buttons.add(SpeedDialChild(
|
buttons.add(SpeedDialChild(
|
||||||
child: Icon(FontAwesomeIcons.plusCircle),
|
child: Icon(FontAwesomeIcons.plusCircle),
|
||||||
label: "Add Test Result",
|
label: "Add Test Result",
|
||||||
onTap: null,
|
onTap: () {
|
||||||
|
addTestResult();
|
||||||
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
return buttons;
|
return buttons;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user