• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

juancastillo0 / json_form / 14147619926

29 Mar 2025 04:54PM UTC coverage: 81.034% (+0.4%) from 80.605%
14147619926

push

github

juancastillo0
fix example rendering test

1739 of 2146 relevant lines covered (81.03%)

1.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.83
/lib/src/fields/shared.dart
1
import 'package:flutter/material.dart';
2
import 'package:json_form/src/builder/logic/widget_builder_logic.dart';
3
import 'package:json_form/src/models/json_form_ui_config.dart';
4

5
export 'package:json_form/src/fields/fields.dart'
6
    show PropertyFieldState, PropertyFieldWidget;
7
export 'package:json_form/src/models/json_form_ui_config.dart';
8

9
class CustomErrorText extends StatelessWidget {
10
  const CustomErrorText({super.key, required this.text});
1✔
11
  final String text;
12

13
  @override
1✔
14
  Widget build(BuildContext context) {
15
    return Padding(
1✔
16
      padding: const EdgeInsets.only(top: 5, bottom: 5),
17
      child: Text(
1✔
18
        text,
1✔
19
        style: WidgetBuilderInherited.of(context).uiConfig.error,
3✔
20
      ),
21
    );
22
  }
23
}
24

25
class WrapFieldWithLabel extends StatelessWidget {
26
  const WrapFieldWithLabel({
1✔
27
    super.key,
28
    required this.formValue,
29
    required this.child,
30
    this.ignoreFieldLabel = false,
31
  });
32

33
  final JsonFormValue formValue;
34
  final Widget child;
35
  final bool ignoreFieldLabel;
36

37
  @override
1✔
38
  Widget build(BuildContext context) {
39
    final property = formValue.schema;
2✔
40
    final directionality = Directionality.of(context);
1✔
41
    final uiConfig = WidgetBuilderInherited.of(context).uiConfig;
2✔
42

43
    Widget child = this.child;
1✔
44
    if (uiConfig.inputWrapperBuilder != null) {
1✔
45
      final wrapped = uiConfig.inputWrapperBuilder!(property, child);
×
46
      if (wrapped != null) child = wrapped;
47
    }
48

49
    if (uiConfig.fieldWrapperBuilder != null) {
1✔
50
      final wrapped = uiConfig.fieldWrapperBuilder!(property, child);
×
51
      if (wrapped != null) return wrapped;
52
    }
53
    // configured in the field itself
54
    final showLabel = ignoreFieldLabel ||
1✔
55
        uiConfig.labelPosition != LabelPosition.input &&
2✔
56
            uiConfig.labelPosition != LabelPosition.table;
2✔
57
    if (!showLabel) return child;
58

59
    final labelText = uiConfig.labelText(formValue);
2✔
60
    final label = Text(
1✔
61
      labelText,
62
      style: uiConfig.fieldLabel,
1✔
63
    );
64
    final mappedChild = uiConfig.labelPosition == LabelPosition.top
2✔
65
        ? child
66
        : Expanded(child: child);
1✔
67
    final space = uiConfig.labelPosition == LabelPosition.top
2✔
68
        ? null
69
        : const SizedBox(width: 20);
70

71
    return Flex(
1✔
72
      direction: uiConfig.labelPosition == LabelPosition.top
2✔
73
          ? Axis.vertical
74
          : Axis.horizontal,
75
      children: directionality == TextDirection.rtl
1✔
76
          ? [mappedChild, if (space != null) space, label]
×
77
          : [label, if (space != null) space, mappedChild],
3✔
78
    );
79
  }
80
}
81

82
class FormSection extends StatelessWidget {
83
  const FormSection({
1✔
84
    super.key,
85
    required this.child,
86
  });
87

88
  final Widget child;
89

90
  @override
1✔
91
  Widget build(BuildContext context) {
92
    final uiConfig = WidgetBuilderInherited.of(context).uiConfig;
2✔
93
    final custom = uiConfig.formSectionBuilder?.call(child);
1✔
94
    if (custom != null) return custom;
95

96
    return Container(
1✔
97
      decoration: BoxDecoration(
1✔
98
        border: Border(
1✔
99
          left: BorderSide(
1✔
100
            color: (DividerTheme.of(context).color ??
2✔
101
                    Theme.of(context).dividerColor)
2✔
102
                .withOpacity(0.2),
1✔
103
          ),
104
        ),
105
      ),
106
      margin: const EdgeInsets.only(top: 7),
107
      padding: const EdgeInsets.only(left: 7),
108
      child: child,
1✔
109
    );
110
  }
111
}
112

113
// ignore: avoid_classes_with_only_static_members
114
class JsonFormKeys {
115
  static const Key submitButton = Key('JsonForm_submitButton');
116
  static const Key scrollView = Key('JsonForm_scrollView');
117

118
  static ValueKey<String> selectDate(String idKey) =>
1✔
119
      ValueKey('JsonForm_selectDate_$idKey');
2✔
120
  static ValueKey<String> selectTime(String idKey) =>
1✔
121
      ValueKey('JsonForm_selectTime_$idKey');
2✔
122
  static ValueKey<String> objectProperty(String idKey) =>
1✔
123
      ValueKey('JsonForm_objectProperty_$idKey');
2✔
124

125
  static Key arrayCheckboxItem(String arrayKey, int index) =>
1✔
126
      Key('JsonForm_item_${arrayKey}_$index');
2✔
127
  static Key arrayItem(String itemKey) => Key('JsonForm_item_$itemKey');
3✔
128
  static Key showOrHideItems(String arrayKey) =>
1✔
129
      Key('JsonForm_showOrHideItems_$arrayKey');
2✔
130

131
  static Key removeItem(String idKey) => Key('removeItem_$idKey');
3✔
132
  static Key addItem(String idKey) => Key('addItem_$idKey');
3✔
133
  static Key copyItem(String idKey) => Key('copyItem_$idKey');
3✔
134

135
  static Key inputField(String idKey) => Key(idKey);
2✔
136
  static Key inputFieldItem(String idKey, int index) => Key('${idKey}_$index');
3✔
137
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc