Skip to content

Commit

Permalink
models: add section
Browse files Browse the repository at this point in the history
  • Loading branch information
arnemolland committed Sep 19, 2024
1 parent 0a4f792 commit de3ed92
Show file tree
Hide file tree
Showing 4 changed files with 296 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/src/converters/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class NodeJsonConverter implements JsonConverter<Node?, Object?> {
return Instance.fromJson(json);
case 'DOCUMENT':
return Document.fromJson(json);
case 'SECTION':
return Section.fromJson(json);
default:
throw UnsupportedError('Unsupported node type : ${node.type}');
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ export 'models/component_node.dart';
export 'models/component_property_type.dart';
export 'models/component_property.dart';
export 'models/overrides.dart';
export 'models/section.dart';
76 changes: 76 additions & 0 deletions lib/src/models/section.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import 'package:figma/src/models/node.dart';
import 'package:figma/src/models/paint.dart';
import 'package:figma/src/models/rectangle.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:copy_with_extension/copy_with_extension.dart';

part 'section.g.dart';

/// Represents a section in the Figma document.
@JsonSerializable()
@CopyWith()
class Section extends Node {
/// Whether the contents of the section are visible.
@JsonKey(defaultValue: false)
final bool contentsHidden;

/// Whether the section is marked Ready for dev or Completed.
/// If the section does not have a status, the property is null.
final String? devStatus;

/// An array of fill paints applied to the node.
@JsonKey(defaultValue: [])
final List<Paint> fills;

/// An array of stroke paints applied to the node.
@JsonKey(defaultValue: [])
final List<Paint> strokes;

/// The weight of strokes on the node.
final double? strokeWeight;

/// Position of stroke relative to vector outline, as a string enum.
final String? strokeAlign;

/// An array of nodes that are contained in the section.
final List<Node> children;

/// Bounding box of the node in absolute space coordinates.
final Rectangle? absoluteBoundingBox;

/// The actual bounds of a node accounting for drop shadows, thick strokes, and anything else that may fall outside the node's regular bounding box.
final Rectangle? absoluteRenderBounds;

Section({
required super.id,
required super.visible,
required this.contentsHidden,
this.devStatus,
required this.fills,
required this.strokes,
this.strokeWeight,
this.strokeAlign,
required this.children,
this.absoluteBoundingBox,
this.absoluteRenderBounds,
});

@override
List<Object?> get props => [
contentsHidden,
devStatus,
fills,
strokes,
strokeWeight,
strokeAlign,
children,
absoluteBoundingBox,
absoluteRenderBounds,
];

factory Section.fromJson(Map<String, dynamic> json) =>
_$SectionFromJson(json);

@override
Map<String, dynamic> toJson() => _$SectionToJson(this);
}
217 changes: 217 additions & 0 deletions lib/src/models/section.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit de3ed92

Please sign in to comment.