Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error to use a list : HiveError : To use this list, you have to open the box "empresas" first. #1288

Open
DoxtorDoz opened this issue May 6, 2024 · 0 comments

Comments

@DoxtorDoz
Copy link

DoxtorDoz commented May 6, 2024

I'm trying to open a box but everytime i try to do that, this Expection happens:

Exception has occurred. HiveError (HiveError: To use this list, you have to open the box "empresas" first.)

The fragment of code that fails is this one:

var boxEmpresas = await Hive.openBox<Empresa>('empresas');

this is the full method:

Future<void> initHive() async {

    await Hive.initFlutter();
    Hive.registerAdapter(EmpresarioAdapter());
    Hive.registerAdapter(EmpresaAdapter());

    var boxEmpresas = await Hive.openBox<Empresa>('empresas');
    var boxEmpresarios = await Hive.openBox<Empresario>('empresarios');
  }

and these are the objects:

import 'package:apiary/objetos/seccion.dart';
import 'package:hive/hive.dart';
import 'package:apiary/objetos/empresario.dart';

part 'empresa.g.dart';

@HiveType(typeId: 1)
class Empresa extends HiveObject {
  @HiveField(0)
  final String id;

  @HiveField(1)
  final String nombre;

  @HiveField(2)
  final Empresario empresario;

  @HiveField(3)
  String password;

  @HiveField(4)
  String? foto;

  @HiveField(5)
  String? descripcion;

  @HiveField(6)
  List<Seccion>? secciones;

  Empresa({
    this.id = '',
    required this.empresario,
    required this.nombre,
    required this.password,
    this.descripcion,
    this.foto,
    this.secciones,
  });
}

import 'package:hive/hive.dart';
import 'package:apiary/objetos/empresa.dart';

part 'empresario.g.dart';

@HiveType(typeId: 0)
class Empresario extends HiveObject {
  @HiveField(0)
  final String id;

  @HiveField(1)
  String? nombre;

  @HiveField(2)
  final String correo;

  @HiveField(3)
  String password;

  @HiveField(4)
  String? telefono;

  @HiveField(5)
  String? foto;

  @HiveField(6)
  List<Empresa>? empresas;

  Empresario({
    this.id = '',
    this.nombre,
    required this.correo,
    required this.password,
    this.telefono,
    this.foto,
    this.empresas,
  });
}

I've been trying to open the 'empresas' box on different parts of the code but none of them worked, even tried to wipe all the data out and got nothing too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant