Skip to content

Instantly share code, notes, and snippets.

@mukhtharcm
Created March 16, 2021 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mukhtharcm/751c909a81fa38bd27594cc2aaaf566b to your computer and use it in GitHub Desktop.
Save mukhtharcm/751c909a81fa38bd27594cc2aaaf566b to your computer and use it in GitHub Desktop.
TypeAdaptor Example for blog
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'note_model.dart';
// **************************************************************************
// TypeAdapterGenerator
// **************************************************************************
class NoteModelAdapter extends TypeAdapter<NoteModel> {
@override
final int typeId = 0;
@override
NoteModel read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return NoteModel()
..title = fields[0] as String
..content = fields[1] as String
..createdTime = fields[2] as DateTime;
}
@override
void write(BinaryWriter writer, NoteModel obj) {
writer
..writeByte(3)
..writeByte(0)
..write(obj.title)
..writeByte(1)
..write(obj.content)
..writeByte(2)
..write(obj.createdTime);
}
@override
int get hashCode => typeId.hashCode;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is NoteModelAdapter &&
runtimeType == other.runtimeType &&
typeId == other.typeId;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment