generateCopyWithMethods static method
String
generateCopyWithMethods({
- required List<
NameType> classFields, - required List<
NameType> interfaceFields, - required String interfaceName,
- required String className,
- required bool isClassAbstract,
- required List<
NameType> interfaceGenerics, - bool generateCopyWithFn = false,
- List<
String> knownClasses = const [], - List<
NameType> classGenerics = const [], - bool nonSealed = false,
- bool hidePublicConstructor = false,
Generate copyWith methods (now generates simple copyWith without patchInput) AND separate patchWith methods
Implementation
static String generateCopyWithMethods({
required List<NameType> classFields,
required List<NameType> interfaceFields,
required String interfaceName,
required String className,
required bool isClassAbstract,
required List<NameType> interfaceGenerics,
bool generateCopyWithFn = false,
List<String> knownClasses = const [],
List<NameType> classGenerics = const [],
bool nonSealed = false,
bool hidePublicConstructor = false,
}) {
final methods = <String>[];
// Generate simple copyWith methods (without patchInput)
final copyWithMethods = MethodGeneratorFacade.generateCopyWithMethods(
classFields: classFields,
interfaceFields: interfaceFields,
interfaceName: interfaceName,
className: className,
isClassAbstract: isClassAbstract,
interfaceGenerics: interfaceGenerics,
generateCopyWithFn: generateCopyWithFn,
knownClasses: knownClasses,
classGenerics: classGenerics,
nonSealed: nonSealed,
hidePublicConstructor: hidePublicConstructor,
);
if (copyWithMethods.isNotEmpty) {
methods.add(copyWithMethods);
}
// Generate separate patchWith methods (with patchInput)
final patchWithMethods = MethodGeneratorFacade.generatePatchWithMethods(
classFields: classFields,
interfaceFields: interfaceFields,
interfaceName: interfaceName,
className: className,
isClassAbstract: isClassAbstract,
interfaceGenerics: interfaceGenerics,
generatePatchWithFn: generateCopyWithFn, // Use same flag for consistency
knownClasses: knownClasses,
classGenerics: classGenerics,
nonSealed: nonSealed,
hidePublicConstructor: hidePublicConstructor,
);
if (patchWithMethods.isNotEmpty) {
methods.add(patchWithMethods);
}
return methods.join('\n\n');
}