2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00

Refactor test result display

This commit is contained in:
Oliver Walters 2020-05-25 22:40:21 +10:00
parent 54f045afd8
commit 393863957e

View File

@ -181,76 +181,55 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
var results = getTestResults(); var results = getTestResults();
for (var item in results) { for (var item in results) {
bool _required = false;
String _test;
bool _result = null;
String _value;
String _notes;
FaIcon _icon = FaIcon(FontAwesomeIcons.questionCircle, color: Color.fromRGBO(0, 0, 250, 1));
bool _valueRequired = false;
bool _attachmentRequired = false;
if (item is InvenTreePartTestTemplate) { if (item is InvenTreePartTestTemplate) {
var template = item as InvenTreePartTestTemplate; _result = item.passFailStatus();
_test = item.testName;
var status = template.passFailStatus(); _required = item.required;
_value = item.latestResult()?.value ?? '';
FaIcon icon; _notes = item.latestResult()?.notes ?? '';
_valueRequired = item.requiresValue;
if (status == null) { _attachmentRequired = item.requiresAttachment;
icon = FaIcon(FontAwesomeIcons.questionCircle, } else if (item is InvenTreeStockItemTestResult) {
color: Color.fromRGBO(0, 0, 250, 0.8) _result = item.result;
); _test = item.testName;
} else if (status == true) { _required = false;
icon = FaIcon(FontAwesomeIcons.checkCircle, _value = item.value;
color: Color.fromRGBO(0, 250, 0, 0.8) _notes = item.notes;
);
} else {
icon = FaIcon(FontAwesomeIcons.timesCircle,
color: Color.fromRGBO(250, 0, 0, 0.8)
);
}
String subtitle = template.latestResult()?.value ?? '';
tiles.add(ListTile(
title: Text("${template.testName}",
style: TextStyle(fontWeight: FontWeight.bold),
),
subtitle: Text(subtitle),
trailing: icon,
onLongPress: () {
addTestResult(
name: template.testName,
nameIsEditable: false,
valueRequired: template.requiresValue,
attachmentRequired: template.requiresAttachment,
);
}
));
} }
else if (item is InvenTreeStockItemTestResult) { if (_result == true) {
var result = item as InvenTreeStockItemTestResult; _icon = FaIcon(FontAwesomeIcons.checkCircle,
color: Color.fromRGBO(0, 250, 0, 0.8)
);
} else if (_result == false) {
_icon = FaIcon(FontAwesomeIcons.timesCircle,
color: Color.fromRGBO(250, 0, 0, 0.8)
);
}
FaIcon icon; tiles.add(ListTile(
title: Text(_test, style: TextStyle(fontWeight: _required ? FontWeight.bold : FontWeight.normal)),
if (result.result == true) { subtitle: Text(_value),
icon = FaIcon(FontAwesomeIcons.checkCircle, trailing: _icon,
color: Color.fromRGBO(0, 250, 0, 0.8) onLongPress: () {
); addTestResult(
} else { name: _test,
icon = FaIcon(FontAwesomeIcons.timesCircle, nameIsEditable: !_required,
color: Color.fromRGBO(250, 0, 0, 0.8) valueRequired: _valueRequired,
attachmentRequired: _attachmentRequired
); );
} }
));
tiles.add(ListTile(
title: Text("${result.testName}"),
subtitle: Text("${result.value}"),
trailing: icon,
onLongPress: () {
addTestResult(
name: result.testName,
nameIsEditable: false,
valueRequired: false,
attachmentRequired: false
);
}
));
}
} }
if (tiles.isEmpty) { if (tiles.isEmpty) {