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

juancastillo0 / json_form / 10820622711

11 Sep 2024 10:26PM UTC coverage: 72.723% (+4.1%) from 68.638%
10820622711

push

github

juancastillo0
dependencies tests

1461 of 2009 relevant lines covered (72.72%)

1.18 hits per line

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

74.63
/lib/src/models/ui_schema.dart
1
class UiSchemaData {
2
  final Map<String, Object?> _asJson = {};
3
  String? title;
4
  String? description;
5
  UiSchemaData? globalOptions;
6
  UiSchemaData? parent;
7
  final Map<String, UiSchemaData> children = {};
8

9
  ///
10
  /// General Options
11
  ///
12
  String? help;
13
  bool readOnly = false;
14
  bool disabled = false;
15
  bool hidden = false;
16
  bool hideError = false;
17

18
  ///
19
  /// String Options
20
  ///
21
  String? placeholder;
22
  String? emptyValue;
23
  bool autofocus = false;
24
  bool autocomplete = false;
25

26
  ///
27
  /// Date Options
28
  ///
29
  List<int>? yearsRange; // TODO: negative values
30

31
  /// Date format MDY, DMY and YMD (default)
32
  String format = 'YMD';
33
  bool hideNowButton = false;
34
  bool hideClearButton = false;
35

36
  /// boolean: radio, select, checkbox (default)
37
  /// string: textarea, password, color, file
38
  /// number: updown, range, radio
39
  /// array: checkboxes
40
  String? widget;
41

42
  /// With "widget=file" or "format=data-url": accept='.pdf'
43
  String? accept;
44

45
  /// Displayed as text if is not empty
46
  List<String>? enumNames;
47
  List<String>? enumDisabled;
48
  List<String>? order;
49

50
  ///
51
  /// Array Options
52
  ///
53
  bool inline = false;
54
  bool addable = true;
55
  bool removable = true;
56
  bool orderable = true;
57
  bool copyable = true;
58

59
  Map<String, Object?> toJson() => {
2✔
60
        'ui:options': _asJson,
2✔
61
        for (final e in children.entries) e.key: e.value.toJson(),
2✔
62
      };
63

64
  void setGlobalOptions(Map<String, Object?> data) {
×
65
    globalOptions ??= UiSchemaData();
×
66
    globalOptions!.setUi(data, parent: this);
×
67
    setUi(data, parent: null);
×
68
  }
69

70
  void setUi(
1✔
71
    Map<String, dynamic> uiSchema, {
72
    required UiSchemaData? parent,
73
    bool fromOptions = false,
74
  }) {
75
    this.parent = parent ?? this.parent;
2✔
76
    if (parent != null &&
77
        parent.globalOptions != null &&
1✔
78
        this != parent.globalOptions) {
×
79
      setGlobalOptions(parent.globalOptions!.toJson());
×
80
    }
81
    // if (fromOptions) {
82
    //   final options = asJson['ui:options'] as Map<String, Object?>? ?? {};
83
    //   asJson['ui:options'] = options;
84
    //   options.addAll(uiSchema);
85
    // } else {
86
    //   asJson.addAll(uiSchema);
87
    // }
88
    uiSchema.forEach((key, data) {
2✔
89
      final split = key.split(':');
1✔
90
      final String k;
91
      if (fromOptions) {
92
        k = key;
93
      } else if (split.length == 2 && split.first == 'ui') {
4✔
94
        k = split.last;
1✔
95
        // } else if (data is Map<String, dynamic>) {
96
        //   final nested = nestedProperties[key] ?? UiSchemaData();
97
        //   nestedProperties[key] = nested;
98
        //   nested.setUi(data, fromOptions: false, parent: this);
99
        //   return;
100
      } else {
101
        return;
102
      }
103
      bool saveInJson = true;
104
      switch (k) {
105
        case "disabled":
1✔
106
          disabled = data as bool;
1✔
107
          break;
108
        // TODO: filePreview, label=false, type:password
109
        // rows/width
110
        case "autofocus":
1✔
111
          autofocus = data as bool;
×
112
          break;
113
        case "autocomplete":
1✔
114
          autocomplete = data as bool;
×
115
          break;
116
        case "hideError":
1✔
117
          hideError = data as bool;
×
118
          break;
119
        case "enumDisabled":
1✔
120
          enumDisabled = (data as List).cast();
2✔
121
          break;
122
        case "enumNames":
1✔
123
          enumNames = (data as List).cast();
2✔
124
          break;
125
        case "emptyValue":
1✔
126
          emptyValue = data as String;
1✔
127
          break;
128
        case "title":
1✔
129
          title = data as String;
1✔
130
          break;
131
        case "description":
1✔
132
          description = data as String;
1✔
133
          break;
134
        case "help":
1✔
135
          help = data as String;
1✔
136
          break;
137
        case "placeholder":
1✔
138
          placeholder = data as String;
1✔
139
          break;
140
        case "readonly":
1✔
141
          readOnly = data as bool;
1✔
142
          break;
143
        case "hidden":
1✔
144
          hidden = data as bool;
1✔
145
          break;
146
        case "widget":
1✔
147
          // TODO: password, textarea, inputType:tel,email?
148
          widget = data as String;
1✔
149
          break;
150
        case "yearsRange":
1✔
151
          yearsRange = data as List<int>;
×
152
          break;
153
        case "format":
1✔
154
          format = data as String;
×
155
          break;
156
        case "hideNowButton":
1✔
157
          hideNowButton = data as bool;
×
158
          break;
159
        case "hideClearButton":
1✔
160
          hideClearButton = data as bool;
×
161
          break;
162
        case "order":
1✔
163
          order = List<String>.from(data);
2✔
164
          break;
165

166
        ///
167
        /// Array Properties
168
        ///
169
        case "addable":
1✔
170
          addable = data as bool;
×
171
          break;
172
        case "removable":
1✔
173
          removable = data as bool;
×
174
          break;
175
        case "orderable":
1✔
176
          orderable = data as bool;
1✔
177
          break;
178
        case "copyable":
1✔
179
          copyable = data as bool;
×
180
          break;
181
        case "options":
1✔
182
          setUi(data as Map<String, Object?>, fromOptions: true, parent: null);
1✔
183
          saveInJson = false;
184
          break;
185
        case "globalOptions":
1✔
186
          setGlobalOptions(data as Map<String, Object?>);
×
187
          break;
188
        default:
189
          saveInJson = false;
190
      }
191
      if (saveInJson) {
192
        _asJson[k] = data;
2✔
193
      }
194
    });
195
  }
196
}
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