buildHashCodeSnippet function
Builds hashCode getter snippet.
Implementation
String buildHashCodeSnippet(
List<
({
String name,
String type,
bool isNamed,
bool isNullable,
bool isCollection,
})
>
fields, {
DartFileEditBuilder? builder,
}) {
if (builder != null && fields.any((f) => f.isCollection)) {
builder.importLibrary(Uri.parse('package:collection/collection.dart'));
}
final hashList = fields
.map((f) {
if (f.isCollection) {
return 'const DeepCollectionEquality().hash(${f.name})';
}
return f.name;
})
.join(', ');
return '''
@override
int get hashCode => Object.hash($hashList);''';
}