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

Duit-Foundation / flutter_duit / 15852670316

24 Jun 2025 02:04PM UTC coverage: 58.702% (+0.8%) from 57.892%
15852670316

push

github

web-flow
feat: AnimatedSlide (#287)

41 of 43 new or added lines in 6 files covered. (95.35%)

1 existing line in 1 file now uncovered.

3997 of 6809 relevant lines covered (58.7%)

8.04 hits per line

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

93.75
/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();
98✔
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
94✔
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),
138✔
68
      ElementType.row => RowAttributes.fromJson(data),
96✔
69
      ElementType.column => ColumnAttributes.fromJson(data),
102✔
70
      ElementType.sizedBox => SizedBoxAttributes.fromJson(data),
92✔
71
      ElementType.center => CenterAttributes.fromJson(data),
94✔
72
      ElementType.coloredBox => ColoredBoxAttributes.fromJson(data),
94✔
73
      ElementType.textField => TextFieldAttributes.fromJson(data),
92✔
74
      ElementType.elevatedButton => ElevatedButtonAttributes.fromJson(data),
96✔
75
      ElementType.stack => StackAttributes.fromJson(data),
98✔
76
      ElementType.expanded => ExpandedAttributes.fromJson(data),
92✔
77
      ElementType.padding => PaddingAttributes.fromJson(data),
92✔
78
      ElementType.positioned => PositionedAttributes.fromJson(data),
90✔
79
      ElementType.decoratedBox => DecoratedBoxAttributes.fromJson(data),
86✔
80
      ElementType.checkbox => CheckboxAttributes.fromJson(data),
88✔
81
      ElementType.container => ContainerAttributes.fromJson(data),
124✔
82
      ElementType.image => ImageAttributes.fromJson(data),
76✔
83
      ElementType.gestureDetector => GestureDetectorAttributes.fromJson(data),
78✔
84
      ElementType.align => AlignAttributes.fromJson(data),
76✔
85
      ElementType.transform => TransformAttributes.fromJson(data),
72✔
86
      ElementType.richText => RichTextAttributes.fromJson(data),
72✔
87
      ElementType.wrap => WrapAttributes.fromJson(data),
74✔
88
      ElementType.custom => _parseCustomWidgetAttributes(json, tag),
72✔
89
      ElementType.lifecycleStateListener =>
68✔
90
        LifecycleStateListenerAttributes.fromJson(data),
×
91
      ElementType.singleChildScrollview =>
68✔
92
        SingleChildScrollviewAttributes.fromJson(data),
2✔
93
      ElementType.radio => RadioAttributes.fromJson(data),
66✔
94
      ElementType.radioGroupContext =>
66✔
95
        RadioGroupContextAttributes.fromJson(data),
×
96
      ElementType.ignorePointer => IgnorePointerAttributes.fromJson(data),
68✔
97
      ElementType.opacity => OpacityAttributes.fromJson(data),
66✔
98
      ElementType.slider => SliderAttributes.fromJson(data),
62✔
99
      ElementType.fittedBox => FittedBoxAttributes.fromJson(data),
64✔
100
      ElementType.switchW => SwitchAttributes.fromJson(data),
60✔
101
      ElementType.meta => MetaAttributes.fromJson(data),
60✔
102
      ElementType.listView => ListViewAttributes.fromJson(data),
62✔
103
      ElementType.repaintBoundary => RepaintBoundaryAttributes.fromJson(data),
60✔
104
      ElementType.overflowBox => OverflowBoxAttributes.fromJson(data),
60✔
105
      ElementType.animatedSize => AnimatedSizeAttributes.fromJson(data),
62✔
106
      ElementType.animatedBuilder => AnimatedBuilderAttributes.fromJson(data),
62✔
107
      ElementType.intrinsicHeight => IntrinsicHeightAttributes.fromJson(data),
54✔
108
      ElementType.intrinsicWidth => IntrinsicWidthAttributes.fromJson(data),
56✔
109
      ElementType.rotatedBox => RotatedBoxAttributes.fromJson(data),
54✔
110
      ElementType.constrainedBox => ConstrainedBoxAttributes.fromJson(data),
52✔
111
      ElementType.backdropFilter => BackdropFilterAttributes.fromJson(data),
50✔
112
      ElementType.animatedOpacity => AnimatedOpacityAttributes.fromJson(data),
50✔
113
      ElementType.safeArea => SafeAreaAttributes.fromJson(data),
44✔
114
      ElementType.gridView => GridViewAttributes.fromJson(data),
42✔
115
      ElementType.subtree ||
40✔
116
      ElementType.component =>
38✔
117
        SubtreeAttributes.fromJson(data),
8✔
118
      ElementType.remoteSubtree => RemoteSubtreeAttributes.fromJson(data),
34✔
119
      ElementType.card => CardAttributes.fromJson(data),
32✔
120
      ElementType.appBar => AppBarAttributes.fromJson(data),
32✔
121
      ElementType.scaffold => ScaffoldAttributes.fromJson(data),
28✔
122
      ElementType.inkWell => InkWellAttributes.fromJson(data),
26✔
123
      ElementType.carouselView => CarouselViewAttributes.fromJson(data),
24✔
124
      ElementType.animatedContainer =>
20✔
125
        AnimatedContainerAttributes.fromJson(data),
2✔
126
      ElementType.animatedAlign => AnimatedAlignAttributes.fromJson(data),
20✔
127
      ElementType.animatedRotation => AnimatedRotationAttributes.fromJson(data),
18✔
128
      ElementType.animatedPadding => AnimatedPaddingAttributes.fromJson(data),
16✔
129
      ElementType.animatedPositioned =>
12✔
130
        AnimatedPositionedAttributes.fromJson(data),
2✔
131
      ElementType.animatedScale => AnimatedScaleAttributes.fromJson(data),
12✔
132
      ElementType.absorbPointer => AbsorbPointerAttributes.fromJson(data),
10✔
133
      ElementType.offstage => OffstageAttributes.fromJson(data),
8✔
134
      ElementType.animatedCrossFade =>
4✔
135
        AnimatedCrossFadeAttributes.fromJson(data),
2✔
136
      ElementType.animatedSlide => AnimatedSlideAttributes.fromJson(data),
4✔
UNCOV
137
      ElementType.empty || String() => EmptyAttributes(),
×
138
    };
139

140
    return ViewAttribute(payload: payload, id: id ?? "null_id");
94✔
141
  }
142
}
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