2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 05:26:47 +00:00

Improve rendering for checkbox fields

This commit is contained in:
Oliver 2021-07-23 12:36:03 +10:00
parent 5c2f747b93
commit 7a6457f870
3 changed files with 38 additions and 15 deletions

View File

@ -6,6 +6,7 @@ import 'package:inventree/l10.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:inventree/widget/snacks.dart';
import 'package:one_context/one_context.dart';
@ -83,16 +84,9 @@ class APIFormField {
return TextFormField(
decoration: InputDecoration(
labelText: required ? label + "*" : label,
labelStyle: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22,
color: hasErrors() ? Color.fromRGBO(250, 50, 50, 1) : Color.fromRGBO(50, 50, 50, 1),
),
labelStyle: _labelStyle(),
helperText: helpText,
helperStyle: TextStyle(
fontStyle: FontStyle.italic,
color: hasErrors() ? Color.fromRGBO(205, 50, 50, 1) : Color.fromRGBO(50, 50, 50, 1),
),
helperStyle: _helperStyle(),
hintText: placeholderText,
),
initialValue: value ?? '',
@ -112,13 +106,31 @@ class APIFormField {
return CheckBoxField(
label: label,
hint: helpText,
labelStyle: _labelStyle(),
helperText: helpText,
helperStyle: _helperStyle(),
initial: value,
onSaved: (val) {
data['value'] = val;
},
);
}
TextStyle _labelStyle() {
return new TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
color: hasErrors() ? Color.fromRGBO(250, 50, 50, 1) : Color.fromRGBO(50, 50, 50, 1),
);
}
TextStyle _helperStyle() {
return new TextStyle(
fontStyle: FontStyle.italic,
color: hasErrors() ? Color.fromRGBO(205, 50, 50, 1) : Color.fromRGBO(50, 50, 50, 1),
);
}
}
@ -166,7 +178,12 @@ Future<void> launchApiForm(BuildContext context, String title, String url, Map<S
var availableFields = extractFields(options);
if (availableFields.isEmpty) {
print("Empty fields {} returned from ${url}");
// User does not have permission to perform this action
showSnackIcon(
L10().response403,
icon: FontAwesomeIcons.userTimes,
);
return;
}

View File

@ -92,17 +92,23 @@ class ImagePickerField extends FormField<File> {
class CheckBoxField extends FormField<bool> {
CheckBoxField({String? label, String? hint, bool initial = false, Function(bool?)? onSaved}) :
CheckBoxField({
String? label, bool initial = false, Function(bool?)? onSaved,
TextStyle? labelStyle,
String? helperText,
TextStyle? helperStyle,
}) :
super(
onSaved: onSaved,
initialValue: initial,
builder: (FormFieldState<bool> state) {
return CheckboxListTile(
//dense: state.hasError,
title: label == null ? null : Text(label),
title: label != null ? Text(label, style: labelStyle) : null,
value: state.value,
onChanged: state.didChange,
subtitle: hint == null ? null : Text(hint),
subtitle: helperText != null ? Text(helperText, style: helperStyle) : null,
contentPadding: EdgeInsets.zero,
);
}
);

View File

@ -84,7 +84,7 @@ class _StockItemTestResultDisplayState extends RefreshableState<StockItemTestRes
),
CheckBoxField(
label: L10().result,
hint: L10().testPassedOrFailed,
helperText: L10().testPassedOrFailed,
initial: true,
onSaved: (value) => _result = value ?? false,
),