In my Flutter App, I have created 4 Hive Box for storing different values but data is inserting in only one box and when I try to insert data noting happening or not giving any exception or error. I have developed code as it is for all 4 box but I am not getting why my data is not inserting in Hive. If you run this project you understand everything..

First Box Model Class Code:

import 'package:hive/hive.dart';

part 'PasswordModel.g.dart';

@HiveType(typeId: 0)
class PasswordModel {
  @HiveField(0)
  final String websiteName;
  @HiveField(1)
  final String websiteAddress;
  @HiveField(2)
  final String userName;
  @HiveField(3)
  final String password;
  @HiveField(4)
  final String notes;

  PasswordModel(
      {this.websiteName, this.websiteAddress, this.userName, this.password, this.notes});
}

Second Box Model Class:

import 'package:hive/hive.dart';

part 'CardModel.g.dart';

@HiveType(typeId: 1)
class CardModel{
  @HiveField(0)
  final String cardName;
  @HiveField(1)
  final String cardNumber;
  @HiveField(2)
  final String userName;
  @HiveField(3)
  final String expiration;
  @HiveField(4)
  final String cvv;
  @HiveField(5)
  final String pin;
  @HiveField(6)
  final String note;

  CardModel({this.cardName, this.cardNumber, this.userName, this.expiration, this.cvv, this.pin, this.note});

}

main.dart:

import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:secret_keeper/screens/SplashScreen.dart';
import 'package:path_provider/path_provider.dart';
import 'package:secret_keeper/Database/Hive/BankModel.dart';
import 'package:secret_keeper/Database/Hive/CardModel.dart';
import 'package:secret_keeper/Database/Hive/NotesModel.dart';
import 'package:secret_keeper/Database/Hive/PasswordModel.dart';

void main(){
  runApp(SecretKeeper());
}

class SecretKeeper extends StatefulWidget {
  @override
  _SecretKeeperState createState() => _SecretKeeperState();
}

class _SecretKeeperState extends State<SecretKeeper> {

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    Hive.registerAdapter(PasswordModelAdapter());
    Hive.registerAdapter(CardModelAdapter());
    Hive.registerAdapter(BankModelAdapter());
    Hive.registerAdapter(NotesModelAdapter());
    _openBox();
  }

  Future _openBox() async {
    WidgetsFlutterBinding.ensureInitialized();
    var dir = await getApplicationDocumentsDirectory();
    Hive.init(dir.path);
    Box passwordBox = await Hive.openBox<PasswordModel>('passwordBox');
    Box cardBox = await Hive.openBox<CardModel>('cardBox');
    Box bankBox = await Hive.openBox<BankModel>('bankBox');
    Box notesBox = await Hive.openBox<NotesModel>('notesBox');
    return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "Secret Keeper",
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        accentColor: Colors.white60,
        primaryColor: Colors.white,
        primaryIconTheme: IconThemeData(color: Colors.black),
        fontFamily: "GoogleFonts",
      ),
      home: SplashScreen(),
    );
  }
}

Class from where I am getting input. I have skipped UI code for better understanding and showed only method which call when User click on Submit button.

Input Class 1 method:

void addDataToHive() {
    PasswordModel passwordModel = PasswordModel(
      websiteName: websiteNameController.text,
      websiteAddress: websiteAddressController.text,
      userName: userNameController.text,
      password: passwordController.text,
      notes: notesController.text
    );
    var passwordBox = Hive.box<PasswordModel>('passwordBox');
    passwordBox.add(passwordModel);
    Navigator.pop(context);
  }

Input Class 2 method:

void addDataToHive() {
    CardModel cardModel = CardModel(
      cardName: cardNameController.text,
      cardNumber: cardNumberController.text,
      userName: userNameController.text,
      expiration: expirationController.text,
      cvv: cvvController.text,
      pin: pinController.text,
      note: notesController.text
    );
    var cardBox = Hive.box<CardModel>('cardBox');
    cardBox.add(cardModel);
    Navigator.pop(context);
  }

This is a class where I show list of data.

First Class Code:

import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:secret_keeper/Database/Hive/PasswordModel.dart';
import 'package:secret_keeper/screens/home_screen/passwords/ShowData.dart';

class PasswordsNavigation extends StatefulWidget {
  @override
  _PasswordsNavigationState createState() => _PasswordsNavigationState();
}

class _PasswordsNavigationState extends State<PasswordsNavigation> {
  var passwordBox = Hive.box<PasswordModel>('passwordBox');

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Expanded(
            child: _buildListView(),
          )
        ],
      ),
    );
  }

  Widget _buildListView() {
    return WatchBoxBuilder(
      box: passwordBox,
      builder: (context, box) {
        Map<dynamic, dynamic> raw = box.toMap();
        List list = raw.values.toList();

        return ListView.builder(
          shrinkWrap: true,
          itemCount: list.length,
          itemBuilder: (context, index) {
            PasswordModel passwordModel = list[index];
            return ListTile(
              title: Text(passwordModel.websiteName),
              subtitle: Text(passwordModel.websiteAddress),
              trailing: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  IconButton(
                    icon: Icon(Icons.delete),
                    onPressed: () {
                      passwordBox.deleteAt(index);
                    },
                  )
                ],
              ),
              onTap: () {
                Navigator.of(context).push(MaterialPageRoute(
                    builder: (_) => ShowData(
                          id: index,
                        )));
              },
            );
          },
        );
      },
    );
  }
}

Second Class Code:

import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:secret_keeper/Database/Hive/CardModel.dart';
import 'package:secret_keeper/screens/home_screen/cards/ShowData.dart';

class CardsNavigation extends StatefulWidget {
  @override
  _CardsNavigationState createState() => _CardsNavigationState();
}

class _CardsNavigationState extends State<CardsNavigation> {
  var cardBox = Hive.box<CardModel>('cardBox');

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Expanded(
            child: _buildListView(),
          )
        ],
      ),
    );
  }

  Widget _buildListView() {
    return WatchBoxBuilder(
      box: cardBox,
      builder: (context, box) {
        Map<dynamic, dynamic> raw = box.toMap();
        List list = raw.values.toList();

        return ListView.builder(
          shrinkWrap: true,
          itemCount: list.length,
          itemBuilder: (context, index) {
            CardModel cardModel = list[index];
            return ListTile(
              title: Text(cardModel.cardName),
              subtitle: Text(cardModel.cardNumber),
              trailing: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  IconButton(
                    icon: Icon(Icons.delete),
                    onPressed: () {
                      cardBox.deleteAt(index);
                    },
                  )
                ],
              ),
              onTap: () {
                Navigator.of(context).push(MaterialPageRoute(
                    builder: (_) => ShowData(
                      id: index,
                    ),
                ),
                );
              },
            );
          },
        );
      },
    );
  }
}

Same I have extra 2 box, but I add reference of 2 Box only, So my problem is data adding in only first box and remaining box not getting any data, but I don't know why?

For Full code Follow this Link: https://github.com/jaydip-pawar/Password-Manager-Flutter.git