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

juancastillo0 / json_form / 11788932365

12 Nov 2024 01:21AM UTC coverage: 80.651% (+6.3%) from 74.365%
11788932365

push

github

juancastillo0
Add more README docs

1659 of 2057 relevant lines covered (80.65%)

1.3 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_schema_style.dart';
4

5
class CustomErrorText extends StatelessWidget {
6
  const CustomErrorText({super.key, required this.text});
1✔
7
  final String text;
8

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

21
class WrapFieldWithLabel extends StatelessWidget {
22
  const WrapFieldWithLabel({
1✔
23
    super.key,
24
    required this.formValue,
25
    required this.child,
26
    this.ignoreFieldLabel = false,
27
  });
28

29
  final JsonFormValue formValue;
30
  final Widget child;
31
  final bool ignoreFieldLabel;
32

33
  @override
1✔
34
  Widget build(BuildContext context) {
35
    final property = formValue.schema;
2✔
36
    final directionality = Directionality.of(context);
1✔
37
    final uiConfig = WidgetBuilderInherited.of(context).uiConfig;
2✔
38

39
    Widget child = this.child;
1✔
40
    if (uiConfig.inputWrapperBuilder != null) {
1✔
41
      final wrapped = uiConfig.inputWrapperBuilder!(property, child);
×
42
      if (wrapped != null) child = wrapped;
43
    }
44

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

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

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

78
class FormSection extends StatelessWidget {
79
  const FormSection({
1✔
80
    super.key,
81
    required this.child,
82
  });
83

84
  final Widget child;
85

86
  @override
1✔
87
  Widget build(BuildContext context) {
88
    final uiConfig = WidgetBuilderInherited.of(context).uiConfig;
2✔
89
    final custom = uiConfig.formSectionBuilder?.call(child);
1✔
90
    if (custom != null) return custom;
91

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

109
// ignore: avoid_classes_with_only_static_members
110
class JsonFormKeys {
111
  static const Key submitButton = Key('JsonForm_submitButton');
112
  static const Key scrollView = Key('JsonForm_scrollView');
113

114
  static ValueKey<String> selectDate(String idKey) =>
1✔
115
      ValueKey('JsonForm_selectDate_$idKey');
2✔
116
  static ValueKey<String> selectTime(String idKey) =>
1✔
117
      ValueKey('JsonForm_selectTime_$idKey');
2✔
118
  static ValueKey<String> objectProperty(String idKey) =>
1✔
119
      ValueKey('JsonForm_objectProperty_$idKey');
2✔
120

121
  static Key arrayCheckboxItem(String arrayKey, int index) =>
1✔
122
      Key('JsonForm_item_${arrayKey}_$index');
2✔
123
  static Key arrayItem(String itemKey) => Key('JsonForm_item_$itemKey');
3✔
124
  static Key showOrHideItems(String arrayKey) =>
1✔
125
      Key('JsonForm_showOrHideItems_$arrayKey');
2✔
126

127
  static Key removeItem(String idKey) => Key('removeItem_$idKey');
3✔
128
  static Key addItem(String idKey) => Key('addItem_$idKey');
3✔
129
  static Key copyItem(String idKey) => Key('copyItem_$idKey');
3✔
130

131
  static Key inputField(String idKey) => Key(idKey);
2✔
132
  static Key inputFieldItem(String idKey, int index) => Key('${idKey}_$index');
3✔
133
}
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