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

Duit-Foundation / flutter_duit / 15436082859

04 Jun 2025 07:18AM UTC coverage: 46.939% (+0.04%) from 46.897%
15436082859

push

github

web-flow
feat: Offstage (#277)

22 of 41 new or added lines in 6 files covered. (53.66%)

1 existing line in 1 file now uncovered.

3128 of 6664 relevant lines covered (46.94%)

6.29 hits per line

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

93.42
/lib/src/utils/attribute_parser.dart
1
import "package:duit_kernel/duit_kernel.dart";
2
import "package:flutter_duit/src/attributes/index.dart";
3
import "package:flutter_duit/src/ui/models/element_type.dart";
4
import "package:flutter_duit/src/utils/index.dart";
5

6
/// The `AttributeParser` class is responsible for parsing and mapping attributes for different DUIT elements.
7
///
8
/// This class provides static methods for parsing custom widget attributes and creating `ViewAttributeWrapper` instances.
9
///
10
/// Usage:
11
/// ```dart
12
/// final attributes = AttributeParser.parse(type, json, tag);
13
/// ```
14
///
15
/// To parse custom widget attributes, you can use the `_parseCustomWidgetAttributes` method.
16
/// This method takes a JSON object and a tag as parameters and returns the parsed attributes.
17
/// ```dart
18
/// final customAttributes = AttributeParser._parseCustomWidgetAttributes(json, tag);
19
/// ```
20
final class DefaultAttributeParser implements AttributeParserBase {
21
  const DefaultAttributeParser();
76✔
22

23
  /// Parses custom widget attributes based on the specified JSON object and tag.
24
  ///
25
  /// This method retrieves the attributes mapper for the given tag from the `DUITRegistry`.
26
  /// If an attributes mapper is found, it is invoked with the tag and JSON object to get the parsed attributes.
27
  /// If no attributes mapper is found, it returns an instance of `EmptyAttributes`.
28
  ///
29
  /// Parameters:
30
  /// - [json]: The JSON object containing the attributes.
31
  /// - [tag]: The tag of the custom widget.
32
  ///
33
  /// Returns:
34
  /// The parsed attributes for the custom widget.
35
  dynamic _parseCustomWidgetAttributes(JSONObject? json, String? tag) {
2✔
36
    assert(tag != null, "Custom widget must have specified tag");
2✔
37

38
    final attributesMapper = DuitRegistry.getAttributesFactory(tag!);
2✔
39
    if (attributesMapper != null) {
40
      return attributesMapper(tag, json);
2✔
41
    } else {
42
      return EmptyAttributes();
×
43
    }
44
  }
45

46
  /// Parses and creates a `ViewAttributeWrapper` instance based on the specified type, JSON object, and tag.
47
  ///
48
  /// This method is used to parse and map attributes for different DUIT elements.
49
  /// It returns a new instance of `ViewAttributeWrapper` with the appropriate payload type based on the element type.
50
  ///
51
  /// Parameters:
52
  /// - [type]: The type of the DUIT element.
53
  /// - [json]: The JSON object representing the attributes of the DUIT element.
54
  /// - [tag]: The tag of the DUIT element (optional for custom widgets).
55
  ///
56
  /// Returns:
57
  /// A `ViewAttributeWrapper` instance with the parsed attributes.
58
  @override
72✔
59
  ViewAttribute<T> parse<T>(
60
    String type,
61
    JSONObject? json,
62
    String? tag, {
63
    String? id,
64
  }) {
65
    final data = json ?? {};
×
66
    final payload = switch (type) {
67
      ElementType.text => TextAttributes.fromJson(data),
110✔
68
      ElementType.row => RowAttributes.fromJson(data),
72✔
69
      ElementType.column => ColumnAttributes.fromJson(data),
78✔
70
      ElementType.sizedBox => SizedBoxAttributes.fromJson(data),
72✔
71
      ElementType.center => CenterAttributes.fromJson(data),
74✔
72
      ElementType.coloredBox => ColoredBoxAttributes.fromJson(data),
74✔
73
      ElementType.textField => TextFieldAttributes.fromJson(data),
72✔
74
      ElementType.elevatedButton => ElevatedButtonAttributes.fromJson(data),
76✔
75
      ElementType.stack => StackAttributes.fromJson(data),
74✔
76
      ElementType.expanded => ExpandedAttributes.fromJson(data),
70✔
77
      ElementType.padding => PaddingAttributes.fromJson(data),
70✔
78
      ElementType.positioned => PositionedAttributes.fromJson(data),
70✔
79
      ElementType.decoratedBox => DecoratedBoxAttributes.fromJson(data),
70✔
80
      ElementType.checkbox => CheckboxAttributes.fromJson(data),
70✔
81
      ElementType.container => ContainerAttributes.fromJson(data),
100✔
82
      ElementType.image => ImageAttributes.fromJson(data),
64✔
83
      ElementType.gestureDetector => GestureDetectorAttributes.fromJson(data),
66✔
84
      ElementType.align => AlignAttributes.fromJson(data),
64✔
85
      ElementType.transform => TransformAttributes.fromJson(data),
60✔
86
      ElementType.richText => RichTextAttributes.fromJson(data),
60✔
87
      ElementType.wrap => WrapAttributes.fromJson(data),
60✔
88
      ElementType.custom => _parseCustomWidgetAttributes(json, tag),
62✔
89
      ElementType.lifecycleStateListener =>
58✔
90
        LifecycleStateListenerAttributes.fromJson(data),
×
91
      ElementType.singleChildScrollview =>
58✔
92
        SingleChildScrollviewAttributes.fromJson(data),
2✔
93
      ElementType.radio => RadioAttributes.fromJson(data),
56✔
94
      ElementType.radioGroupContext =>
56✔
95
        RadioGroupContextAttributes.fromJson(data),
×
96
      ElementType.ignorePointer => IgnorePointerAttributes.fromJson(data),
56✔
97
      ElementType.opacity => OpacityAttributes.fromJson(data),
58✔
98
      ElementType.slider => SliderAttributes.fromJson(data),
54✔
99
      ElementType.fittedBox => FittedBoxAttributes.fromJson(data),
54✔
100
      ElementType.switchW => SwitchAttributes.fromJson(data),
54✔
101
      ElementType.meta => MetaAttributes.fromJson(data),
54✔
102
      ElementType.listView => ListViewAttributes.fromJson(data),
56✔
103
      ElementType.repaintBoundary => RepaintBoundaryAttributes.fromJson(data),
54✔
104
      ElementType.overflowBox => OverflowBoxAttributes.fromJson(data),
54✔
105
      ElementType.animatedSize => AnimatedSizeAttributes.fromJson(data),
56✔
106
      ElementType.animatedBuilder => AnimatedBuilderAttributes.fromJson(data),
56✔
107
      ElementType.intrinsicHeight => IntrinsicHeightAttributes.fromJson(data),
48✔
108
      ElementType.intrinsicWidth => IntrinsicWidthAttributes.fromJson(data),
50✔
109
      ElementType.rotatedBox => RotatedBoxAttributes.fromJson(data),
48✔
110
      ElementType.constrainedBox => ConstrainedBoxAttributes.fromJson(data),
46✔
111
      ElementType.backdropFilter => BackdropFilterAttributes.fromJson(data),
44✔
112
      ElementType.animatedOpacity => AnimatedOpacityAttributes.fromJson(data),
44✔
113
      ElementType.safeArea => SafeAreaAttributes.fromJson(data),
38✔
114
      ElementType.gridView => GridViewAttributes.fromJson(data),
36✔
115
      ElementType.subtree ||
34✔
116
      ElementType.component =>
32✔
117
        SubtreeAttributes.fromJson(data),
8✔
118
      ElementType.remoteSubtree => RemoteSubtreeAttributes.fromJson(data),
28✔
119
      ElementType.card => CardAttributes.fromJson(data),
26✔
120
      ElementType.appBar => AppBarAttributes.fromJson(data),
26✔
121
      ElementType.scaffold => ScaffoldAttributes.fromJson(data),
22✔
122
      ElementType.inkWell => InkWellAttributes.fromJson(data),
20✔
123
      ElementType.carouselView => CarouselViewAttributes.fromJson(data),
18✔
124
      ElementType.animatedContainer =>
14✔
125
        AnimatedContainerAttributes.fromJson(data),
2✔
126
      ElementType.animatedAlign => AnimatedAlignAttributes.fromJson(data),
14✔
127
      ElementType.animatedRotation => AnimatedRotationAttributes.fromJson(data),
12✔
128
      ElementType.animatedPadding => AnimatedPaddingAttributes.fromJson(data),
10✔
129
      ElementType.animatedPositioned =>
6✔
130
        AnimatedPositionedAttributes.fromJson(data),
2✔
131
      ElementType.animatedScale => AnimatedScaleAttributes.fromJson(data),
6✔
132
      ElementType.offstage => OffstageAttributes.fromJson(data),
4✔
UNCOV
133
      ElementType.empty || String() => EmptyAttributes(),
×
134
    };
135

136
    return ViewAttribute(payload: payload, id: id ?? "null_id");
72✔
137
  }
138
}
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