8000 Wrong generator result for empty classes · Issue #1081 · isar/hive · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Wrong generator result for empty classes #1081
Open
@maeddin

Description

@maeddin

Steps to Reproduce
Create an empty class with the HiveType annotation.

@HiveType(typeId: 0)
class EmptyClass {}

Start the generator. The result is:

class EmptyClassAdapter extends TypeAdapter<EmptyClass> {
  @override
  final int typeId = 58;

  @override
  EmptyClass read(BinaryReader reader) {
    return EmptyClass();
  }

  @override
  void write(BinaryWriter writer, EmptyClass obj) {
    writer.writeByte(0);
  }

  @override
  int get hashCode => typeId.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is EmptyClassAdapter &&
          runtimeType == other.runtimeType &&
          typeId == other.typeId;
}

But the correct result should be:

class EmptyClassAdapter extends TypeAdapter<EmptyClass> {
  @override
  final int typeId = 58;

  @override
  EmptyClass read(BinaryReader reader) {
    final numOfFields = reader.readByte();
    final fields = <int, dynamic>{
      for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
    };
    return EmptyClass();
  }

  @override
  void write(BinaryWriter writer, EmptyClass obj) {
    writer.writeByte(0);
  }

  @override
  int get hashCode => typeId.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is EmptyClassAdapter &&
          runtimeType == other.runtimeType &&
          typeId == other.typeId;
}

Version

  • Platform: -
  • Flutter version: 3.3.2
  • Hive version: 2.2.3
  • Hive generator version: 1.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    problemAn unconfirmed bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0