constructorParameters function
String
constructorParameters(
- ConstructorElement constructor, {
- Set<DartType>? skip,
})
Implementation
String constructorParameters(
final ConstructorElement constructor, {
Set<DartType>? skip,
}) {
String arg = "", storeing = "";
bool hasNamed = false;
List<String> sharedInstances = [];
for (var par in constructor.parameters) {
if (skip?.contains(par.type) ?? false) continue;
if (par.isNamed && !hasNamed) {
hasNamed = true;
arg += "{";
}
arg +=
"${(hasNamed && par.isRequired) ? 'required ' : ''}${par.type} ${par.name}${par.hasDefaultValue ? ' = ${par.defaultValueCode}' : ''},";
storeing += "_${par.name} = ${par.name},";
}
if (sharedInstances.isNotEmpty) {
if (!hasNamed) {
arg += "{";
hasNamed = true;
}
arg += sharedInstances.join("");
}
if (hasNamed) arg += "}";
if (arg.isNotEmpty) {
return "($arg):${storeing.substring(0, storeing.length - 1)}";
}
return "($arg)";
}