Line data Source code
1 : part of apptive_grid_form_widgets;
2 :
3 : /// FormComponent Widget to display a [BooleanFormComponent]
4 : class CheckBoxFormWidget extends StatefulWidget {
5 : /// Creates a [Checkbox] to display a boolean value contained in [component]
6 3 : const CheckBoxFormWidget({
7 : Key? key,
8 : required this.component,
9 3 : }) : super(key: key);
10 :
11 : /// Component this Widget should reflect
12 : final BooleanFormComponent component;
13 :
14 2 : @override
15 2 : _CheckBoxFormWidgetState createState() => _CheckBoxFormWidgetState();
16 : }
17 :
18 : class _CheckBoxFormWidgetState extends State<CheckBoxFormWidget> {
19 2 : @override
20 : Widget build(BuildContext context) {
21 2 : return FormField<bool>(
22 8 : initialValue: widget.component.data.value,
23 1 : validator: (value) {
24 3 : if (widget.component.required && !value!) {
25 : return 'Required';
26 : } else {
27 : return null;
28 : }
29 : },
30 : autovalidateMode: AutovalidateMode.onUserInteraction,
31 2 : builder: (state) {
32 2 : return InputDecorator(
33 2 : decoration: InputDecoration(
34 8 : helperText: widget.component.options.description,
35 : helperMaxLines: 100,
36 2 : errorText: state.errorText,
37 : contentPadding: EdgeInsets.zero,
38 : border: InputBorder.none,
39 : errorBorder: InputBorder.none,
40 : isDense: true,
41 : filled: false,
42 : ),
43 2 : child: ColorFiltered(
44 2 : colorFilter: ColorFilter.mode(
45 4 : Theme.of(context).errorColor,
46 2 : state.hasError ? BlendMode.srcATop : BlendMode.dstIn,
47 : ),
48 2 : child: Row(
49 : crossAxisAlignment: CrossAxisAlignment.center,
50 2 : children: [
51 2 : SizedBox(
52 : height: 24,
53 : width: 24,
54 2 : child: Checkbox(
55 8 : value: widget.component.data.value,
56 1 : onChanged: (newValue) {
57 4 : widget.component.data.value = newValue;
58 1 : state.didChange(newValue);
59 2 : setState(() {});
60 : },
61 : ),
62 : ),
63 : const SizedBox(
64 : width: 4,
65 : ),
66 2 : Expanded(
67 2 : child: Text(
68 14 : widget.component.options.label ?? widget.component.property,
69 : ),
70 : ),
71 : ],
72 : ),
73 : ),
74 : );
75 : },
76 : );
77 : }
78 : }
|