@@ -510,7 +510,7 @@ class CodeChunks {
510
510
paramValueCode = fieldReaders[index];
511
511
if (entity.properties[index].isRelation) {
512
512
if (paramDartType.startsWith ('ToOne<' )) {
513
- paramValueCode = 'ToOne (targetId: $paramValueCode )' ;
513
+ paramValueCode = '$ paramDartType (targetId: $paramValueCode )' ;
514
514
} else if (paramType == 'optional-named' ) {
515
515
log.info ('Skipping constructor parameter $paramName on '
516
516
"'${entity .name }': the matching field is a relation but the type "
@@ -519,7 +519,7 @@ class CodeChunks {
519
519
}
520
520
}
521
521
} else if (paramDartType.startsWith ('ToMany<' )) {
522
- paramValueCode = 'ToMany ()' ;
522
+ paramValueCode = '$ paramDartType ()' ;
523
523
} else {
524
524
// If we can't find a positional param, we can't use the constructor at all.
525
525
if (paramType == 'positional' || paramType == 'required-named' ) {
@@ -533,14 +533,22 @@ class CodeChunks {
533
533
return true ; // continue to the next param
534
534
}
535
535
536
+ // The Dart Formatter consumes a large amount of time if constructor
537
+ // parameters are complex expressions, so add a variable for each
538
+ // parameter instead and pass that to the constructor.
539
+ // As the parameter name is user supplied add a suffix to avoid collision
540
+ // with other variables of the generated method.
541
+ final paramVar = "${paramName }Param" ;
542
+ preLines.add ("final $paramVar = $paramValueCode ;" );
543
+
536
544
switch (paramType) {
537
545
case 'positional' :
538
546
case 'optional' :
539
- constructorLines.add (paramValueCode );
547
+ constructorLines.add (paramVar );
540
548
break ;
541
549
case 'required-named' :
542
550
case 'optional-named' :
543
- constructorLines.add ('$paramName : $paramValueCode ' );
551
+ constructorLines.add ('$paramName : $paramVar ' );
544
552
break ;
545
553
default :
546
554
throw InvalidGenerationSourceError (
0 commit comments