hive icon indicating copy to clipboard operation
hive copied to clipboard

Requesting typeAdpter for DateTime type

Open joceljunior opened this issue 2 years ago • 3 comments

Future saveSessionCache(Session? session) async { session!.id = sessionCacheId; var box = await hive.openBox<Session>(sessionCacheBox); await box.clear(); await box.put(session.id, session);

return true;

}

When I'm trying to save my Session object to the box, I get the following error:

Error: HiveError: Cannot write, unknown type: DateTime. Did you forget to register an adapter?

This error I'm facing in previous versions too!

  • Platform: Web
  • Flutter version: [2.10.5]
  • Hive version: [2.1.0]

joceljunior avatar May 24 '22 13:05 joceljunior

I have a doubt that you called to Hive.initFlutter instead of using Hive.init directly? The problem is that DateTime adapter is one of the internal adapters that would be registered when calling the Hive.init method. While using Hive.initFlutter would return immediately without calling to the lower layer init method for web.

image

daothanhduy305 avatar May 25 '22 04:05 daothanhduy305

Same issue with me. Working fine in Android but not in Web. This is happening after upgrading to hive 2.2.1 from 2.0.6

tusharlock10 avatar May 28 '22 22:05 tusharlock10

Waiting for this to be released, as this is breaking our app on web.

ahetawal-p avatar Jun 01 '22 18:06 ahetawal-p