From 7a6457f870fb0c35852919bd8d1b1a63db5a2b48 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 23 Jul 2021 12:36:03 +1000 Subject: [PATCH] Improve rendering for checkbox fields --- lib/api_form.dart | 39 ++++++++++++++++++------- lib/widget/fields.dart | 12 ++++++-- lib/widget/stock_item_test_results.dart | 2 +- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/lib/api_form.dart b/lib/api_form.dart index 3e4bc60b..ed74752f 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -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 launchApiForm(BuildContext context, String title, String url, Map { class CheckBoxField extends FormField { - 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 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, ); } ); diff --git a/lib/widget/stock_item_test_results.dart b/lib/widget/stock_item_test_results.dart index 0851224e..66adf0d2 100644 --- a/lib/widget/stock_item_test_results.dart +++ b/lib/widget/stock_item_test_results.dart @@ -84,7 +84,7 @@ class _StockItemTestResultDisplayState extends RefreshableState _result = value ?? false, ),