Skip to content

Commit 3d75db9

Browse files
committed
update data class macro for latest apis
1 parent 479faaa commit 3d75db9

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

working/macros/example/data_class.dart

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,18 @@ const autoConstructor = _AutoConstructor();
6969
// parameters in this constructor.
7070
for (var param in superconstructor.positionalParameters) {
7171
var requiredKeyword = param.isRequired ? 'required' : '';
72-
var defaultValue = param.defaultValue == null
73-
? ''
74-
: Code.fromParts([' = ', param.defaultValue!]);
7572
parts.addAll([
7673
'\n$requiredKeyword',
7774
param.type.code,
7875
' ${param.identifier.name},',
79-
defaultValue,
80-
',',
8176
]);
8277
}
8378
for (var param in superconstructor.namedParameters) {
8479
var requiredKeyword = param.isRequired ? '' : 'required ';
85-
var defaultValue = param.defaultValue == null
86-
? ''
87-
: Code.fromParts([' = ', param.defaultValue!]);
8880
parts.addAll([
8981
'\n$requiredKeyword',
9082
param.type.code,
91-
' ${param.identifier.name}',
92-
defaultValue,
93-
',',
83+
' ${param.identifier.name},',
9484
]);
9585
}
9686
}
@@ -131,14 +121,16 @@ const copyWith = _CopyWith();
131121
var allFields = await clazz.allFields(builder).toList();
132122
var namedParams = [
133123
for (var field in allFields)
134-
ParameterCode.fromParts(
135-
[field.type.code, '? ${field.identifier.name}']),
124+
ParameterCode(
125+
name: field.identifier.name,
126+
type: field.type.code.asNullable,
127+
keywords: const [],
128+
defaultValue: null),
136129
];
137130
var args = [
138131
for (var field in allFields)
139-
NamedArgumentCode.fromString(
140-
'${field.identifier.name}: ${field.identifier.name} '
141-
'?? this.${field.identifier.name}'),
132+
'${field.identifier.name}: ${field.identifier.name} '
133+
'?? this.${field.identifier.name}',
142134
];
143135
builder.declareInClass(DeclarationCode.fromParts([
144136
clazz.identifier,

working/macros/example/run.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ final myClassFields = [
186186
definingClass: myClassIdentifier,
187187
id: RemoteInstance.uniqueId,
188188
identifier: IdentifierImpl(id: RemoteInstance.uniqueId, name: 'myString'),
189-
initializer: null,
190189
isExternal: false,
191190
isFinal: true,
192191
isLate: false,
@@ -195,7 +194,6 @@ final myClassFields = [
195194
definingClass: myClassIdentifier,
196195
id: RemoteInstance.uniqueId,
197196
identifier: IdentifierImpl(id: RemoteInstance.uniqueId, name: 'myBool'),
198-
initializer: null,
199197
isExternal: false,
200198
isFinal: true,
201199
isLate: false,
@@ -215,7 +213,6 @@ final myClassMethods = [
215213
namedParameters: [],
216214
positionalParameters: [
217215
ParameterDeclarationImpl(
218-
defaultValue: null,
219216
id: RemoteInstance.uniqueId,
220217
identifier: IdentifierImpl(id: RemoteInstance.uniqueId, name: 'other'),
221218
isNamed: false,

0 commit comments

Comments
 (0)