Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapter problem with Implementation of DataTime class #880

Closed
kherel opened this issue Jan 11, 2022 · 2 comments · Fixed by #927
Closed

Adapter problem with Implementation of DataTime class #880

kherel opened this issue Jan 11, 2022 · 2 comments · Fixed by #927
Labels
question Further information is requested

Comments

@kherel
Copy link

kherel commented Jan 11, 2022

Question
I have my own implementation of DataTime class, called TimeWithTimeZone, I need it to save dates with different time zone offsets.
I have many adapters in my project and TimeWithTimeZoneAdapter is only one of them..

The problem is that when I’m saving TimeWithTimeZone object, it’s not calling write method, but saving it as DateTime

Code sample

class TimeWithTimeZone implements DateTime {
	..
	final DateTime _utc
	final Duration offset;
}

class TimeWithTimeZoneAdapter extends TypeAdapter<TimeWithTimeZone> {
  @override
  final int typeId = HiveAdapters.timeWithTimeZone;

  @override
  TimeWithTimeZone read(BinaryReader reader) {
    final string = reader.readString();
    return TimeWithTimeZone.parse(string);
  }

  @override
  void write(BinaryWriter writer, TimeWithTimeZone obj) {
    writer.writeString(obj.toIso8601String());
  }

  @override
  int get hashCode => typeId.hashCode;

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

Version

  • Platform: iOS, Android
  • Flutter version: 2.8.1 • channel stable
  • Hive version: 2.0.5
@kherel kherel added the question Further information is requested label Jan 11, 2022
@kherel
Copy link
Author

kherel commented Jan 11, 2022

I think my question is very similar to this one #821

@saibotma
Copy link
Contributor

Is there any solution to this problem already?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants