top of page

How to save a List<Object> and retrieve using Hive?

  • 작성자 사진: sewookori
    sewookori
  • 2022년 9월 30일
  • 1분 분량

Step 1: Add those dependencies on pubspec.yaml file

dependencies:
  hive: ^2.2.3
  hive_flutter: ^1.1.0

dev_dependencies:
  hive_generator: ^1.1.3
  build_runner: ^[latest version]

Step 2: Make the class like this

part 'wallpaper.g.dart';

@HiveType(typeId: 0, adapterName: "WallpaperAdapter")
class Wallpaper{

  @HiveField(0)
  final String date;

  @HiveField(1)
  final String url;

  Wallpaper({required this.date, required this.url});

}

Step 3: Run the command on terminal

1. flutter packages pub run build_runner build

                      or

2. flutter packages pub run build_runner watch --delete-conflicting-outputs

Step 4: Now register the adapter on main.dart

  void main() async {

  WidgetsFlutterBinding.ensureInitialized();
  await Hive.initFlutter();
  Hive.registerAdapter(WallpaperAdapter());
  await Hive.openBox('myBox');

  runApp(MyApp());
}

Step 5: Now restart your application and let's enjoy 😊


 
 
 

최근 게시물

전체 보기
Fake Artist Topic Generator Custom Excel Files

가짜 예술가 주제 생성기에 사용되는 기본 데이터베이스 파일들입니다. 다운로드 받은 후 편집해서 자신만의 커스텀 데이터베이스를 만들어 사용할 수 있습니다. The files below are basic database files for Fake...

 
 
 

댓글


bottom of page