comparableHelper function

String comparableHelper(
  1. String className,
  2. String getterProps,
  3. String? entityName,
  4. AnnotationData annotationData,
)

Implementation

String comparableHelper(
  String className,
  String getterProps,
  String? entityName,
  AnnotationData annotationData,
) {
  return """
mixin _\$$className${annotationData.genericAugmented ? "<T>" : ""} {
  $getterProps

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    if (other.runtimeType != runtimeType) return false;
    if (other is! $className) return false;

    final thisProps = props;
    final otherProps = other.props;

    if (thisProps.length != otherProps.length) return false;

    for (var i = 0; i < thisProps.length; i++) {
      if (thisProps[i] != otherProps[i]) return false;
    }
    return true;
  }

  @override
  String toString();

  _\$${className}CopyWith${annotationData.genericAugmented ? "<T>" : ""} get copyWith;
  ${annotationData.toJson ? "\nMap<String, dynamic> toJson(${annotationData.genericAugmented ? "T? Function(Object? value) toJsonT" : ""});\n" : ""}
  ${annotationData.toEntity && entityName != null ? "\n$entityName toEntity();\n" : ""}
  ${annotationData.hiveObjectName != null && annotationData.toHiveObject ? "\n${annotationData.hiveObjectName} toHiveObject();\n" : ""}
  @override
  int get hashCode => Object.hashAll(props);

  List<Object?> get props;
}
""";
}