2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +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/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:inventree/widget/snacks.dart';
import 'package:one_context/one_context.dart'; import 'package:one_context/one_context.dart';
@ -83,16 +84,9 @@ class APIFormField {
return TextFormField( return TextFormField(
decoration: InputDecoration( decoration: InputDecoration(
labelText: required ? label + "*" : label, labelText: required ? label + "*" : label,
labelStyle: TextStyle( labelStyle: _labelStyle(),
fontWeight: FontWeight.bold,
fontSize: 22,
color: hasErrors() ? Color.fromRGBO(250, 50, 50, 1) : Color.fromRGBO(50, 50, 50, 1),
),
helperText: helpText, helperText: helpText,
helperStyle: TextStyle( helperStyle: _helperStyle(),
fontStyle: FontStyle.italic,
color: hasErrors() ? Color.fromRGBO(205, 50, 50, 1) : Color.fromRGBO(50, 50, 50, 1),
),
hintText: placeholderText, hintText: placeholderText,
), ),
initialValue: value ?? '', initialValue: value ?? '',
@ -112,13 +106,31 @@ class APIFormField {
return CheckBoxField( return CheckBoxField(
label: label, label: label,
hint: helpText, labelStyle: _labelStyle(),
helperText: helpText,
helperStyle: _helperStyle(),
initial: value, initial: value,
onSaved: (val) { onSaved: (val) {
data['value'] = 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); var availableFields = extractFields(options);
if (availableFields.isEmpty) { 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; return;
} }

View File

@ -92,17 +92,23 @@ class ImagePickerField extends FormField<File> {
class CheckBoxField extends FormField<bool> { 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( super(
onSaved: onSaved, onSaved: onSaved,
initialValue: initial, initialValue: initial,
builder: (FormFieldState<bool> state) { builder: (FormFieldState<bool> state) {
return CheckboxListTile( return CheckboxListTile(
//dense: state.hasError, //dense: state.hasError,
title: label == null ? null : Text(label), title: label != null ? Text(label, style: labelStyle) : null,
value: state.value, value: state.value,
onChanged: state.didChange, 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( CheckBoxField(
label: L10().result, label: L10().result,
hint: L10().testPassedOrFailed, helperText: L10().testPassedOrFailed,
initial: true, initial: true,
onSaved: (value) => _result = value ?? false, onSaved: (value) => _result = value ?? false,
), ),