Flutter Students Club & Zemin Istanbul workshop Hive App

Overview

Hive In Flutter

Made for Zemin Istanbul Presantation

Basically, the application saves the basic data types and custom generated data classes to the local storage.

Getting Started

Dependencies 🧰

Package

dependencies:
  hive_flutter: ^1.1.0 //add this line

dev_dependencies:
  build_runner: ^2.2.1 //add this line
  hive_generator: ^1.1.3 //add this line
  • hive_flutter

Provides operations on the local storage.

  • build_runner

Provides a concrete way of generating files using Dart code.

  • hive_generator

Provides automatic generation of TypeAdapters for almost any class.

Project Architecture Output

.
├── lib                  
    ├── core
        └── service
            ├── cache
                ├── base_cache_manager.dart
                └── cache_enums.dart   
    ├── model
        ├── todo_model.dart
        └── todo_model.g.dart
    └── product
        └── todo
            ├── todo_service.dart
            └── todo_view.dart
└── main.dart

Base Functions & Hive Classes

Base Functions

  • Initialize Hive
  await Hive.initFlutter();
  • Open Hive Box
Future<void> boxInit() async {
  await Hive.openBox(boxName);
}
  • Add item to box with auto increment key
Future<void> addItemWithAutoIncrementKey(T item) async {
  await _box!.add(item);
}
  • Add item to box with custom key
Future<void> addItemWithCustomKey(dynamic key, T item) async {
  await _box!.put(key, item);
}
  • Get item from box
T? getItem(dynamic key) {
  return _box!.get(key);
}
  • Remove item from box
Future<void> removeItem(dynamic key) async {
  await _box!.delete(key);
}
  • Clear box
Future<void> clearBox() async {
  await _box!.clear();
}
  • Close box
Future<void> closeBox() async {
  await _box!.close();
}

Hive Classes

  • Class Architecture
import 'package:hive_flutter/adapters.dart';
part 'todo_model.g.dart';

@HiveType(typeId: 1)
class Todo {
  @HiveField(0)
  int? userId;
  @HiveField(1)
  int? id;
  @HiveField(2)
  String? title;
  @HiveField(3)
  bool? completed;

  Todo({this.userId, this.id, this.title, this.completed});

  Todo.fromJson(Map<String, dynamic> json) {...}
  Map<String, dynamic> toJson() {...}
}
  • Generate Part File Command
flutter pub run build_runner build

Create an Manager from Generic Cache Manager

  • initialize
final BaseCacheManager<Todo> _todoCacheManager = BaseCacheManager<Todo>(boxName: CacheBoxNames.todo);
Future<void> serviceInit() async {
  await _todoCacheManager.boxInit();
}

Usage 🛠

When the manager is generated and initialized, it can accesses and uses generic cache manager functions.

await _todoCacheManager.boxInit();
_todoCacheManager.getItemList();
await _todoCacheManager.addItemList(items);
await _todoCacheManager.clearBox();
...

Source

Hive Documentation

You might also like...

Flutter todo - Simple To-do application created with Flutter and Hive

Flutter todo - Simple To-do application created with Flutter and Hive

To-do app Simple To-do application created with Flutter and Hive. Description Fi

Jan 24, 2022

Pokedex-Flutter - Pokedex demonstrates modern Flutter development with GetX, Hive, Flow, Adaptive/Responsive Design

Pokedex-Flutter - Pokedex demonstrates modern Flutter development with GetX, Hive, Flow, Adaptive/Responsive Design

Pokedex-Flutter Pokedex demonstrates modern Flutter development with GetX, Hive,

Aug 17, 2022

Persist data with Flutter's Hive NoSQL Database locally on Android, iOS & Web.

Persist data with Flutter's Hive NoSQL Database locally on Android, iOS & Web.

Flutter Tutorial - Hive NoSQL Database Persist data with Flutter's Hive NoSQL Database locally on Android, iOS & Web. ✌  Preview App Preview Course Pr

Dec 31, 2022

A flutter boilerplate project containing bloc, pedantic, hive, easy_translations and more!

A flutter boilerplate project containing bloc, pedantic, hive, easy_translations and more!

Flutter Production Boilerplate A flutter project containing bloc, flutter_lints, hive, easy_translations and more! This repository is the starting poi

Dec 26, 2022

Udemy Course "Dart and Flutter: The Complete Developer's Guide" Project. (With Hive DB)

Udemy-Course-Flutter Udemy Course "Dart and Flutter: The Complete Developer's Guide" Project. (With Hive DB) The course: https://www.udemy.com/course/

Jun 11, 2022

GoodBudget - A budget monitor or expense tracker Flutter application that persists data with Hive NoSQL database.

GoodBudget - A budget monitor or expense tracker Flutter application that persists data with Hive NoSQL database.

GoodBudget - A budget monitor or expense tracker Flutter application that persists data with Hive NoSQL database. This cross platform application is available on Android, iOS & Web. Both expenses and income are monitored.

Sep 19, 2022

A flutter project containing riverpod, flutter_lints, hive, easy_translations and more!

 A flutter project containing riverpod, flutter_lints, hive, easy_translations and more!

Flutter Production Boilerplate Riverpod A flutter project containing riverpod, flutter_lints, hive, easy_translations and more! This repository is the

Dec 27, 2022

StudentTester - Simple Flutter app that teachers can use to test students

Student Tester flutter application Getting Started This project is a starting po

Jan 25, 2022

Academic master is E-learning app where students can share their doubts wiith their peers they can chat and also they can find their notes

Academic master is E-learning app where students can share their doubts wiith their peers they can chat and also they can find their notes

Academic Master is E-learning App. Features:- 1) You can post real Post query in Images and video formates. 2) We will Provide notes,books and previou

Dec 14, 2022
Owner
Fluttter Students Club
For now, Turkey's influential Flutter/Dart club is a team that produces, shares and develops content. Learning with you. 🖤
Fluttter Students Club
Hive Wait provide a Hive repository to calling methods in the box as async.

Hive Wait provide a Hive repository to calling methods in the box as async.

Giáo Hồ 1 May 10, 2022
Blog Club | Flutter UI Challenge

Blog Club | Flutter UI Challenge Create navigation like Instagram app navigation Increase performance and reduce memory consumption when scrolling bet

null 3 Aug 16, 2022
A simple flutter workshop project

workshop A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this

Marcelo Esser 3 Jun 13, 2021
Code for the "That's how we scroll in Flutter" workshop

flutter_custom_scroll A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you st

Widgeters 5 Nov 11, 2022
Workshop Flutter สอนน้องๆ ที่ พิษนุโลก

คอร์ส สอน Flutter ตัวต่อต่อ เลือก หัวข้อเรียนได้ Workshop With มาสเตอร์ อึ่ง ต้องการรายละเอียดเพิ่ม หรือ ต้องการ ปรึกษาการทำ โปรเจคแอนดรอยด์ ติดต่อมาส

มาสเตอร์ อึ่ง 0 Nov 27, 2021
Flutter ToDo App - A simple ToDo App made with Flutter and Hive

Flutter ToDo App A simple ToDo App made with Flutter and Hive. ✨ Features Create,Delete,Update tasks. Create Subtasks. Star important Tasks. ?? Screen

null 3 Aug 4, 2022
Hive CRUD App For Flutter

flutter_hive_crud_app A new Flutter project. Getting Started This project is a s

Dagmar de Matos Mpheio 1 Oct 19, 2022
Flutter App Change Theme With Getx and Save Theme Stage with Hive

Flutter Change app Theme With GetX Flutter App Change Theme With Getx. Theme Stage saved using Hive. instead of hive you can use get-storage or shared

Azraf Al Monzim 12 Oct 22, 2022
(Flutter)Minimal App With Offline Storage(Using HIVE) Functionality.

TaskZ (Minimal + Offline TODO List App) Minimal App With Offline Storage(Using HIVE) Functionality. Getting Started ?? Any suggestion, improvement on

null 2 Oct 2, 2022