eqImpl function Null safety

String eqImpl(
  1. String className,
  2. List<String> fieldNames
)

Implementation

String eqImpl(String className, List<String> fieldNames) {
  const other = r'__other$';
  var fieldsEq = 'true';
  if (fieldNames.isNotEmpty) {
    fieldsEq = fieldNames.map((name) => 'this.$name == $other.$name').join(' && ');
  }
  return '''@override
    bool operator ==(Object $other) {
      if (identical(this, $other)) return true;
      if (this.runtimeType != $other.runtimeType) return false;
      return $other is $className && $fieldsEq;
    }''';
}