|
| 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 | +} |
0 commit comments