buildToStringSnippet function
Code generation helpers (kept in one place to avoid duplication) Builds a toString() override snippet for the given class and fields.
Implementation
/// Builds a toString() override snippet for the given class and fields.
String buildToStringSnippet(String className, Iterable<String> fieldNames) {
final fieldsText = fieldNames.isNotEmpty
? fieldNames.map((f) => '$f: \$$f').join(', ')
: '';
return '''
@override
String toString() {
return '$className{$fieldsText}';
}
''';
}