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

juancastillo0 / json_form / 13743422655

09 Mar 2025 01:23AM UTC coverage: 80.521% (-0.01%) from 80.534%
13743422655

push

github

juancastillo0
ui schema width property

7 of 10 new or added lines in 3 files covered. (70.0%)

20 existing lines in 2 files now uncovered.

1670 of 2074 relevant lines covered (80.52%)

1.31 hits per line

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

83.33
/lib/src/builder/object_schema_builder.dart
1
import 'package:flutter/material.dart';
2
import 'package:json_form/json_form.dart';
3
import 'package:json_form/src/builder/general_subtitle_widget.dart';
4
import 'package:json_form/src/builder/logic/object_schema_logic.dart';
5
import 'package:json_form/src/builder/logic/widget_builder_logic.dart';
6
import 'package:json_form/src/builder/widget_builder.dart';
7
import 'package:json_form/src/fields/shared.dart';
8
import 'package:json_form/src/models/models.dart';
9

10
class ObjectSchemaBuilder extends StatefulWidget {
11
  ObjectSchemaBuilder({
1✔
12
    Key? key,
13
    required this.mainSchema,
14
    required this.schemaObject,
15
    // TODO: validate array key
16
  }) : super(key: key ?? ValueKey(schemaObject));
2✔
17

18
  final Schema mainSchema;
19
  final SchemaObject schemaObject;
20

21
  @override
1✔
22
  State<ObjectSchemaBuilder> createState() => _ObjectSchemaBuilderState();
1✔
23
}
24

25
class _ObjectSchemaBuilderState extends State<ObjectSchemaBuilder>
26
    implements JsonFormField<Map<String, Object?>> {
27
  late SchemaObject _schemaObject;
28
  late final JsonFormValue fromValue;
29

30
  @override
1✔
31
  void initState() {
32
    super.initState();
1✔
33
    _schemaObject = widget.schemaObject;
3✔
34
    fromValue =
1✔
35
        PrivateJsonFormController.setField(context, _schemaObject, this);
3✔
36
    syncValues();
1✔
37
  }
38

39
  @override
1✔
40
  void didUpdateWidget(covariant ObjectSchemaBuilder oldWidget) {
41
    super.didUpdateWidget(oldWidget);
1✔
42
    if (oldWidget.schemaObject != widget.schemaObject) {
4✔
43
      _schemaObject = widget.schemaObject;
×
44
      syncValues();
×
45
    }
46
  }
47

48
  void syncValues() {
1✔
49
    fromValue.children.removeWhere(
3✔
50
      (c) =>
1✔
51
          _schemaObject.properties.every((p) => p.id != c.id) &&
7✔
52
              c.dependentsAddedBy.isEmpty ||
×
53
          c.parent?.schema != _schemaObject,
4✔
54
    );
55
    final added = Set.of(fromValue.children.map((c) => c.id));
6✔
56
    fromValue.children.addAll(
3✔
57
      _schemaObject.properties.where((p) => !added.contains(p.id)).map((e) {
8✔
58
        return JsonFormValue(
1✔
59
          id: e.id,
1✔
60
          parent: fromValue,
1✔
61
          schema: e,
62
        );
63
      }),
64
    );
65
  }
66

67
  @override
1✔
68
  Widget build(BuildContext context) {
69
    final properties =
70
        _schemaObject.properties.where((p) => !p.uiSchema.hidden);
6✔
71
    final directionality = Directionality.of(context);
1✔
72
    final widgetBuilderInherited = WidgetBuilderInherited.of(context);
1✔
73
    final uiConfig = widgetBuilderInherited.uiConfig;
1✔
74
    final isTableLabel = uiConfig.labelPosition == LabelPosition.table;
2✔
75
    final objectKey = fromValue.idKey;
2✔
76

77
    final Set<Schema> dependentSchemas = {};
78
    for (final property in properties) {
2✔
79
      if (property is SchemaProperty && property.dependents?.schema != null) {
3✔
80
        dependentSchemas.add(property.dependents!.schema!);
3✔
81
      }
82
    }
83
    final widths = _schemaObject.properties
2✔
84
        .where((p) => !p.uiSchema.hidden)
4✔
85
        .map((e) => e.uiSchema.width)
4✔
86
        .toSet();
1✔
87

88
    return ObjectSchemaInherited(
1✔
89
      schemaObject: _schemaObject,
1✔
90
      listen: (value) {
1✔
91
        if (value is ObjectSchemaDependencyEvent) {
1✔
92
          setState(() => _schemaObject = value.schemaObject);
4✔
93
        }
94
      },
95
      child: FormSection(
1✔
96
        child: Column(
1✔
97
          crossAxisAlignment: CrossAxisAlignment.start,
98
          children: [
1✔
99
            if (!isTableLabel || widget.schemaObject.parent is! SchemaArray)
4✔
100
              GeneralSubtitle(
1✔
101
                field: widget.schemaObject,
2✔
102
                mainSchema: widget.mainSchema,
2✔
103
              ),
104
            if (isTableLabel)
105
              Table(
1✔
106
                columnWidths: widths.length == 1 && widths.first != null
3✔
NEW
107
                    ? {1: FixedColumnWidth(widths.first!)}
×
108
                    : null,
109
                children: [
1✔
110
                  ...fromValue.children
2✔
111
                      .where((c) => c.schema is SchemaProperty)
4✔
112
                      .expand(
1✔
113
                    (e) {
1✔
114
                      final r = (e.schema as SchemaProperty).dependents?.schema;
3✔
115
                      return r != null && e.isDependentsActive
1✔
116
                          ? [
1✔
117
                              e,
118
                              ...((r is SchemaObject) ? r.properties : [r]).map(
3✔
119
                                (s) => JsonFormValue(
2✔
120
                                  id: s.id,
1✔
121
                                  parent: fromValue,
1✔
122
                                  schema: s,
123
                                ),
124
                              ),
125
                            ]
126
                          : [e];
1✔
127
                    },
128
                  ).map(
1✔
129
                    (e) {
1✔
130
                      final s = e.schema;
1✔
131
                      final title =
132
                          uiConfig.titleAndDescriptionBuilder?.call(s) ??
1✔
133
                              Column(
1✔
134
                                crossAxisAlignment: CrossAxisAlignment.start,
135
                                children: [
1✔
136
                                  const SizedBox(height: 15),
137
                                  Text(
1✔
138
                                    s.titleOrId,
1✔
139
                                    style: uiConfig.fieldLabel,
1✔
140
                                  ),
141
                                  if (s.description != null)
1✔
142
                                    Text(
×
143
                                      s.description!,
×
144
                                      style: uiConfig.description,
×
145
                                    ),
146
                                ],
147
                              );
148
                      return TableRow(
1✔
149
                        key: JsonFormKeys.objectProperty(
1✔
150
                          JsonFormKeyPath.appendId(objectKey, e.id),
2✔
151
                        ),
152
                        children: [
1✔
153
                          if (directionality == TextDirection.ltr) title,
2✔
154
                          FormFromSchemaBuilder(
1✔
155
                            schemaObject: widget.schemaObject,
2✔
156
                            mainSchema: widget.mainSchema,
2✔
157
                            formValue: e,
158
                          ),
159
                          if (directionality == TextDirection.rtl) title,
1✔
160
                        ],
161
                      );
162
                    },
163
                  ),
164
                ],
165
              ),
166
            ...fromValue.children
2✔
167
                .where(
1✔
168
                  (p) =>
1✔
169
                      !isTableLabel ||
170
                      p.schema is! SchemaProperty &&
2✔
171
                          !dependentSchemas.contains(p.schema),
2✔
172
                )
173
                .map(
1✔
174
                  (e) => FormFromSchemaBuilder(
2✔
175
                    key: JsonFormKeys.objectProperty(
1✔
176
                      JsonFormKeyPath.appendId(objectKey, e.id),
2✔
177
                    ),
178
                    schemaObject: widget.schemaObject,
2✔
179
                    mainSchema: widget.mainSchema,
2✔
180
                    formValue: e,
181
                  ),
182
                ),
183
          ],
184
        ),
185
      ),
186
    );
187
  }
188

189
  @override
×
190
  Map<String, Object?> get value => fromValue.toJson()! as Map<String, Object?>;
×
191
  @override
192
  final FocusNode focusNode = FocusNode();
193
  @override
×
194
  String get idKey => fromValue.idKey;
×
195
  @override
×
196
  JsonSchemaInfo get property => widget.schemaObject;
×
197

198
  @override
×
199
  set value(Map<String, Object?> newValue) {
200
    newValue.forEach((k, v) {
×
201
      fromValue.children.firstWhere((c) => c.id == k).field!.value = v;
×
202
    });
203
    for (final c in fromValue.children) {
×
204
      if (!newValue.containsKey(c.id)) {
×
205
        c.field!.value = null;
×
206
      }
207
    }
208
  }
209
}
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