{"id":20910253,"url":"https://github.com/arpitaswal/hivedatabase","last_synced_at":"2025-10-09T09:34:38.127Z","repository":{"id":262574840,"uuid":"887421536","full_name":"ArpitAswal/HiveDatabase","owner":"ArpitAswal","description":"Hive is a lightweight and fast NoSQL database that can be used to store data in Flutter applications. By using Hive in our Flutter applications, we can easily store and retrieve data without the overhead of traditional SQL databases.","archived":false,"fork":false,"pushed_at":"2024-11-13T05:49:12.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-12T22:26:46.136Z","etag":null,"topics":["dart","flut","hive-database"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ArpitAswal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-12T18:02:57.000Z","updated_at":"2024-11-13T05:49:15.000Z","dependencies_parsed_at":"2024-11-13T06:36:23.593Z","dependency_job_id":null,"html_url":"https://github.com/ArpitAswal/HiveDatabase","commit_stats":null,"previous_names":["arpitaswal/hivedatabase"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ArpitAswal/HiveDatabase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArpitAswal%2FHiveDatabase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArpitAswal%2FHiveDatabase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArpitAswal%2FHiveDatabase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArpitAswal%2FHiveDatabase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ArpitAswal","download_url":"https://codeload.github.com/ArpitAswal/HiveDatabase/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ArpitAswal%2FHiveDatabase/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271760483,"owners_count":24816427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","flut","hive-database"],"created_at":"2024-11-18T14:14:23.605Z","updated_at":"2025-10-09T09:34:33.106Z","avatar_url":"https://github.com/ArpitAswal.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Project Title: Hive Database Integration in FLutter\n\nHive is a lightweight and fast NoSQL database that can be used to store data in Flutter applications. In this repo, we will explore how to setup and use Hive database in Flutter.\n\nIn this repo, we’ll go over these steps to build a simple CRUD app that stores animals data with hive:\n\n. Setup Hive\n\n. Type Adapters\n\n. Storing data\n\n. Reading data\n\n. Update and Delete data\n\n## Step 1. Setup Hive\n\nTo use Hive in Flutter, we need to add the following dependencies to the pubspec.yaml file:\n\ndependencies:\n\n  hive: ^2.2.3\n\n  hive_flutter: ^1.1.0\n\nwe also need to add hive_generator and build_runner to the dev dependencies:\n\ndev_dependencies:\n\n  hive_generator: ^2.0.0\n\n  build_runner: ^2.3.3\n\nNext, we need to initialize Hive in the main() function of our Flutter application. We can do this by calling the Hive.initFlutter() method as shown below:\n\nvoid main() async {\n\n  await Hive.initFlutter();\n\n  runApp(const MyApp());\n\n}\n\n## Step 2: Define Hive Type Adapters\n\nHive is a NoSQL database that stores data in key-value pairs. Where value can be of a different type such as int, string, list, or custom objects. To store custom objects in Hive, we need to define type adapters that tell Hive how to serialize and deserialize our objects. We can use the hive_generator package to generate type adapters for our custom objects automatically.\n\nIt's a simple model class, which is compatible with Hive \n\nimport 'package:hive/hive.dart';\npart 'animal_model.g.dart';\n\n@HiveType(typeId: 0)\n\nclass AnimalModel {\n\n  @HiveField(0)\n\n  final String name;\n\n  @HiveField(1)\n\n  final String age;\n\n  @HiveField(2)\n\n  final bool isMale;\n\n  const AnimalModel(this.name, this.age, this.isMale);\n}\n\n## NOTE:\n\n. Make sure you add this line in your model class before running the next step.\n\npart 'your_model_class_file.g.dart';\n\n. Annotate the model class with @HiveType(), so the generator knows this should be a TypeAdapter.\n\n. Annotate each field you want to save with @HiveField(index), the index is an int and each index should appear once and you shouldn't change it after registering them.\n\n. In case you change the field name or its datatype or add a new field — You have to run the type adapter command again and re-run the app to reflect the changes in the app.\n\nWe can then generate the type adapters for this class by running the following command in the terminal:\n\n=\u003e flutter packages pub run build_runner build\n\nThis will generate a animal_model.g.dart file that contains the type adapter for our AnimalModel class.\n\nFinally, register the type adapter in your main function, just add it beneath your hive initialization.\n\nvoid main() async {\n\n  await Hive.initFlutter();\n\n  Hive.registerAdapter(AnimalModelAdapter());\n\n  runApp(const MyApp());\n}\n\n## Step 3: Storing Data in Hive\nTo store data in Hive, we need to open a Hive box. A box is similar to a table in a traditional SQL database and stores key-value pairs. We can open a box by calling the Hive.openBox() method and passing in the name of the box as a parameter. For example, we can open a box named animals as shown below:\n\nHive.openBox\u003cAnimalModel\u003e('animals');\n\nWe can open the same box multiple times, returning us the same box instance. However, it is good practice to open it once on app launch and get the box whenever we want to add/update/delete data from it. To get the animal box, we can do the following:\n\nBox\u003cAnimalModel\u003e box = Hive.box\u003cAnimalModel\u003e('animals');\n\nAnd there are 2 ways to add data\n\n. box.add(value) - just gives each value an index and auto increments it.\n\n. box.put('key', value) - you have to specify the key for each value\n\nFor example:  \nvar value = AnimalModel('cat', 8 , false); //creating object\nawait box.put(value.name, value); //putting object into hive box\n\n## Step 4: Reading Data from Hive\nThere are different ways to read data from your boxes:\n\n. box.get('key) - get the value from a key.\n\n. box.getAt(index) - get the value from an index created with box.add().\n\n. box.values - this returns an iterable containing all the items in the box.\n\nFor example:\n\nAnimalModel? value = box.get('cat'); //get by key\nAnimalModel? value = box.getAt(0); //get by index\nList\u003cAnimalModel\u003e? list = box.values.toList(); //get all items in list\n\n## Step 5: Updating Data in Hive\nThere are two ways to update the value\n\n. box.put('key', newValue) to update that value.\n\n. box.putAt(index, item) which works like getAt().\n\nFor example:\n\nvar value = AnimalModel('dog', 8, true); //creating new object \nawait box.put(value.name, value); //putting object into hive box\n\n## Step 6: Deleting Data from Hive\nDeleting items is similar to getting:\n\n. box.delete('key) - delete by key\n\n. box.deleteAt(index) - delete by index\n\n. box.deleteAll(keys) - accepts an iterable of keys, and deletes all the keys given.\n\nFor example:\n\nawait box.delete('cat'); //delete cat with key name 'cat'.\n\n## Finally\nwe have explored how to set up and use Hive in Flutter, including defining Hive type adapters, and storing, reading, updating, and deleting data from Hive. By using Hive in our Flutter applications, we can easily store and retrieve data without the overhead of traditional SQL databases.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farpitaswal%2Fhivedatabase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farpitaswal%2Fhivedatabase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farpitaswal%2Fhivedatabase/lists"}