diff --git a/lib/hive.dart b/lib/hive.dart index ed5d8f023..59c0671dc 100644 --- a/lib/hive.dart +++ b/lib/hive.dart @@ -7,9 +7,9 @@ import 'dart:isolate' if (dart.library.html) 'package:hive/src/impl/isolate_stub.dart'; import 'package:hive/src/impl/frame.dart'; -import 'package:isar/isar.dart'; +import 'package:isar_plus/isar_plus.dart'; -part 'src/impl/box_impl.dart'; -part 'src/impl/type_registry.dart'; part 'src/box.dart'; part 'src/hive.dart'; +part 'src/impl/box_impl.dart'; +part 'src/impl/type_registry.dart'; diff --git a/lib/src/hive.dart b/lib/src/hive.dart index 3f106f107..865975f72 100644 --- a/lib/src/hive.dart +++ b/lib/src/hive.dart @@ -37,9 +37,10 @@ class Hive { /// ``` static void registerAdapter( String typeName, - T? Function(dynamic json) fromJson, - ) { - _typeRegistry.register(Isar.fastHash(typeName), fromJson); + T? Function(dynamic json) fromJson, [ + Type? type, + ]) { + _typeRegistry.register(Isar.fastHash(typeName), fromJson, type); } /// Get or open the box with [name] in the given [directory]. If no directory diff --git a/lib/src/impl/frame.dart b/lib/src/impl/frame.dart index 084ba1f48..b7a5cf737 100644 --- a/lib/src/impl/frame.dart +++ b/lib/src/impl/frame.dart @@ -1,4 +1,4 @@ -import 'package:isar/isar.dart'; +import 'package:isar_plus/isar_plus.dart'; part 'frame.g.dart'; diff --git a/lib/src/impl/type_registry.dart b/lib/src/impl/type_registry.dart index c8e0d7e8b..80399cead 100644 --- a/lib/src/impl/type_registry.dart +++ b/lib/src/impl/type_registry.dart @@ -12,14 +12,18 @@ class _TypeRegistry { final Map> _registry = {}; final Map> _reverseRegistry = {..._builtinTypes}; - void register(int typeId, T? Function(dynamic json) fromJson) { + void register( + int typeId, + T? Function(dynamic json) fromJson, + Type? type, + ) { if (T == dynamic) { throw ArgumentError('Cannot register dynamic type.'); } final handler = _TypeHandler(typeId, fromJson); _registry[typeId] = handler; - _reverseRegistry[T] = handler; + _reverseRegistry[type ?? T] = handler; } T fromJson(int? typeId, dynamic json) { diff --git a/pubspec.yaml b/pubspec.yaml index 790179f50..6c0a6a3e4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,7 @@ environment: sdk: ">=3.1.0 <4.0.0" dependencies: - isar: ^4.0.0-dev.13 + isar_plus: ^1.0.4 meta: ^1.9.0 dev_dependencies: diff --git a/test/common.dart b/test/common.dart index 2a6d503c4..8820f38aa 100644 --- a/test/common.dart +++ b/test/common.dart @@ -4,7 +4,7 @@ import 'dart:math'; import 'package:hive/hive.dart'; import 'package:hive/src/impl/frame.dart'; -import 'package:isar/isar.dart'; +import 'package:isar_plus/isar_plus.dart'; import 'package:test/test.dart'; const _releases = 'https://github.com/isar/isar/releases/download/';