LoginSignup
0
0

More than 1 year has passed since last update.

HiveのopenBoxが成功しない。

Posted at

エラー内容

main.dartで  await Hive.openBox<HabitsManage>('habitsManage'); をしていると下記のようなエラーが必ず出るようになっていた。


E/flutter (10625): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type 'bool' is not a subtype of type 'String' in type cast

考察

Adapter もちゃんと定義しているし bool 型がここに入ってくるようにはならないようにしているのに何故かエラーが出る。もしかしたらデバッグの途中で bool 型の値がアプリ内のストレージに保存されてしまい、それで型のエラーが出ているのではないかと推察。


import 'package:hive/hive.dart';
part 'habits_manage.g.dart'; // ファイル名

@HiveType(typeId: 1)
class HabitsManage {
  HabitsManage(this.title, this.description, this.type, this.image_1);

  @HiveField(0)
  final String title;

  @HiveField(1)
  final String? description;

  @HiveField(2)
  final String type;

  @HiveField(3)
  final String image_1;
}


解決策

一旦デバッグに使っている端末のアプリに入っているアンインストール。そうするとAndroidではアプリ内ストレージが削除されるので不正なデータが消えて、解決した。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0