11import 'package:codelessly_json_annotation/codelessly_json_annotation.dart' ;
22
3+ import '../field_access.dart' ;
34import '../mixins.dart' ;
45import '../models/models.dart' ;
56import 'nodes.dart' ;
@@ -19,11 +20,7 @@ const MaterialIcon defaultIcon = MaterialIcon(
1920/// A node that displays an icon.
2021@JsonSerializable ()
2122class IconNode extends SceneNode
22- with
23- BlendMixin ,
24- SingleColorMixin ,
25- FixedAspectRatioMixin ,
26- CustomPropertiesMixin {
23+ with BlendMixin , FixedAspectRatioMixin , CustomPropertiesMixin {
2724 /// Strictly used for previews. e.g in components panel.
2825 IconNode .empty ()
2926 : this (
@@ -45,6 +42,16 @@ class IconNode extends SceneNode
4542 @override
4643 double get aspectRatio => 1 ;
4744
45+ @override
46+ late final Map <String , FieldAccess <Object ?>> fields = {
47+ 'properties' : ObjectFieldAccess <IconProperties >(
48+ () => 'Properties' ,
49+ () => 'Icon properties' ,
50+ () => properties,
51+ (value) => properties = value,
52+ ),
53+ };
54+
4855 /// Creates an [IconNode] with the given data.
4956 IconNode ({
5057 IconModel ? icon,
@@ -74,15 +81,20 @@ class IconNode extends SceneNode
7481 InkWellModel ? inkWell,
7582 List <Reaction > reactions = const [],
7683 IconProperties ? properties,
77- }) : properties = properties ?? IconProperties (icon: icon ?? defaultIcon) {
84+ }) : properties = properties ??
85+ IconProperties (
86+ icon: MultiSourceIconModel .icon (
87+ icon: icon ?? defaultIcon,
88+ color: color,
89+ ),
90+ ) {
7891 setBlendMixin (
7992 opacity: opacity,
8093 isMask: isMask,
8194 effects: effects,
8295 blendMode: blendMode,
8396 inkWell: inkWell,
8497 );
85- setSingleColorMixin (color: color);
8698 setReactionMixin ([...reactions]);
8799 }
88100
@@ -98,9 +110,21 @@ class IconNode extends SceneNode
98110 if (json.containsKey ('icon' ) && ! json.containsKey ('properties' )) {
99111 json['properties' ] = < String , dynamic > {
100112 'icon' : json['icon' ],
113+ 'show' : true ,
114+ 'color' : json['color' ],
101115 };
102116 json.remove ('icon' );
103117 }
118+ if (json.containsKey ('properties' ) && json['properties' ]['icon' ]['icon' ] == null ) {
119+ // Backwards compatibility for migration to MultiSourceIconModel.
120+ json['properties' ]['icon' ] = {
121+ 'icon' : {
122+ 'icon' : json['properties' ]['icon' ],
123+ 'show' : true ,
124+ 'color' : json['color' ],
125+ },
126+ };
127+ }
104128 return _$IconNodeFromJson (json);
105129 }
106130
@@ -110,9 +134,9 @@ class IconNode extends SceneNode
110134
111135/// Properties for an [IconNode] .
112136@JsonSerializable ()
113- class IconProperties extends CustomProperties {
137+ class IconProperties extends CustomProperties with FieldsHolder {
114138 /// The icon to display.
115- IconModel icon;
139+ MultiSourceIconModel icon;
116140
117141 /// Creates [IconProperties] with the given data.
118142 IconProperties ({
@@ -127,4 +151,14 @@ class IconProperties extends CustomProperties {
127151
128152 @override
129153 List <Object ?> get props => [icon];
154+
155+ @override
156+ late final Map <String , FieldAccess <Object ?>> fields = {
157+ 'icon' : IconFieldAccess (
158+ () => 'Icon' ,
159+ () => 'Icon to display' ,
160+ () => icon,
161+ (value) => icon = value,
162+ ),
163+ };
130164}
0 commit comments