Skip to content

Commit c7d5457

Browse files
committed
External Component Node #1
1 parent 8524082 commit c7d5457

File tree

4 files changed

+169
-4
lines changed

4 files changed

+169
-4
lines changed

lib/src/api/node_json_converter.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import 'package:json_annotation/json_annotation.dart';
99
import 'nodes/nodes.dart';
1010

1111
/// A deserializer function that takes a map as input and deserializes it into
12-
/// a [SceneNode].
13-
typedef JsonNodeDeserializer = SceneNode? Function(Map<dynamic, dynamic> json);
12+
/// a [BaseNode].
13+
typedef JsonNodeDeserializer = BaseNode? Function(Map<dynamic, dynamic> json);
1414

1515
/// [NodeJsonConverter] deserializes JSON and converts it into nodes.
1616
///
@@ -73,6 +73,7 @@ class NodeJsonConverter implements JsonConverter<BaseNode?, Map> {
7373
'listView': ListViewNode.fromJson,
7474
'pageView': PageViewNode.fromJson,
7575
'tabBar': TabBarNode.fromJson,
76+
'external': ExternalComponentNode.fromJson,
7677
};
7778
}
7879

@@ -103,7 +104,7 @@ class NodeJsonConverter implements JsonConverter<BaseNode?, Map> {
103104
@override
104105
BaseNode? fromJson(Map json) {
105106
if (json['type'] == null || _registry[json['type']] == null) {
106-
throw UnsupportedError('Unsupported node type : ${json["type"]}');
107+
throw UnsupportedError('Unsupported node type: ${json["type"]}');
107108
}
108109
return _registry[json['type']]!(json);
109110
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2022, Codelessly.
2+
// All rights reserved. Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE.md file.
4+
5+
import 'package:json_annotation/json_annotation.dart';
6+
7+
import '../mixins.dart';
8+
import '../models/models.dart';
9+
import 'nodes.dart';
10+
11+
part 'external_component_node.g.dart';
12+
13+
/// An inert node that does nothing.
14+
/// This is populated dynamically through the Codelessly SDK.
15+
@JsonSerializable()
16+
class ExternalComponentNode extends BaseNode with CustomPropertiesMixin {
17+
@override
18+
final String type = 'external';
19+
20+
/// A user-defined ID that is used to map this node to a widget builder.
21+
/// The reason we allow an external ID is to allow users to define friendly
22+
/// names for their dynamic nodes instead of arbitrarily-generated IDs.
23+
/// Another reason is that the ID can be used more than once to map multiple
24+
/// nodes to the same widget builder.
25+
String? builderID;
26+
27+
/// Creates an [ExternalComponentNode] with the given data.
28+
ExternalComponentNode({
29+
required super.id,
30+
required super.name,
31+
required super.basicBoxLocal,
32+
required this.builderID,
33+
super.outerBoxLocal,
34+
super.retainedOuterBoxLocal,
35+
super.visible,
36+
super.rotationDegrees,
37+
super.alignment,
38+
super.margin,
39+
super.padding,
40+
super.horizontalFit,
41+
super.verticalFit,
42+
super.flex,
43+
super.constraints,
44+
super.edgePins,
45+
super.aspectRatioLock,
46+
super.positioningMode,
47+
});
48+
49+
/// Creates a [ExternalComponentNode] from a JSON object.
50+
factory ExternalComponentNode.fromJson(Map json) =>
51+
_$ExternalComponentNodeFromJson(json);
52+
53+
@override
54+
Map toJson() => _$ExternalComponentNodeToJson(this);
55+
}

lib/src/api/nodes/external_component_node.g.dart

Lines changed: 108 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/nodes/nodes.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export 'canvas_node.dart';
1111
export 'checkbox_node.dart';
1212
export 'divider_node.dart';
1313
export 'dropdown_node.dart';
14+
export 'external_component_node.dart';
1415
export 'embedded_video_node.dart';
1516
export 'expansion_tile_node.dart';
1617
export 'floating_action_button_node.dart';
@@ -33,10 +34,10 @@ export 'single_placeholder_node.dart';
3334
export 'slider_node.dart';
3435
export 'spacer_node.dart';
3536
export 'switch_node.dart';
37+
export 'tab_bar_node.dart';
3638
export 'text_field_node.dart';
3739
export 'text_node.dart';
3840
export 'variance_node.dart';
3941
export 'web_view_google_maps_properties.dart';
4042
export 'web_view_node.dart';
4143
export 'web_view_twitter_properties.dart';
42-
export 'tab_bar_node.dart';

0 commit comments

Comments
 (0)