Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

models: add section #34

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading