From 45f96ffada03a9a571fc6d42568cd83cd9739fc6 Mon Sep 17 00:00:00 2001 From: Rexios Date: Tue, 3 Sep 2024 12:38:47 -0400 Subject: [PATCH] Add initializer list example --- hive_generator/example/lib/types.dart | 10 +++++++++- hive_generator/example/lib/types.g.dart | 7 +++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/hive_generator/example/lib/types.dart b/hive_generator/example/lib/types.dart index 7d27d69d..a1c65b65 100644 --- a/hive_generator/example/lib/types.dart +++ b/hive_generator/example/lib/types.dart @@ -81,7 +81,12 @@ class IterableClass { @HiveType(typeId: 6) class ConstructorDefaults { - ConstructorDefaults({this.a = 42, this.b = '42', this.c = true}); + ConstructorDefaults({ + this.a = 42, + this.b = '42', + this.c = true, + DateTime? d, + }) : d = d ?? DateTime.now(); @HiveField(0) final int a; @@ -91,6 +96,9 @@ class ConstructorDefaults { @HiveField(2) final bool c; + + @HiveField(3) + final DateTime d; } @HiveType(typeId: 7) diff --git a/hive_generator/example/lib/types.g.dart b/hive_generator/example/lib/types.g.dart index 47e6e896..2d4bf6cc 100644 --- a/hive_generator/example/lib/types.g.dart +++ b/hive_generator/example/lib/types.g.dart @@ -179,19 +179,22 @@ class ConstructorDefaultsAdapter extends TypeAdapter { a: fields[0] == null ? 42 : (fields[0] as num).toInt(), b: fields[1] == null ? '6 * 7' : fields[1] as String, c: fields[2] == null ? true : fields[2] as bool, + d: fields[3] as DateTime?, ); } @override void write(BinaryWriter writer, ConstructorDefaults obj) { writer - ..writeByte(3) + ..writeByte(4) ..writeByte(0) ..write(obj.a) ..writeByte(1) ..write(obj.b) ..writeByte(2) - ..write(obj.c); + ..write(obj.c) + ..writeByte(3) + ..write(obj.d); } @override