feat: добавить поддержку Tag и TransactionRecord в Hive
This commit is contained in:
@@ -11,13 +11,23 @@ class HiveService {
|
||||
static Future<void> init() async {
|
||||
await Hive.initFlutter();
|
||||
|
||||
Hive.registerAdapter(CategoryAdapter());
|
||||
Hive.registerAdapter(TagAdapter());
|
||||
Hive.registerAdapter(TransactionRecordAdapter());
|
||||
// Регистрация адаптеров
|
||||
if (!Hive.isAdapterRegistered(CategoryAdapter().typeId)) {
|
||||
Hive.registerAdapter(CategoryAdapter());
|
||||
}
|
||||
if (!Hive.isAdapterRegistered(TagAdapter().typeId)) {
|
||||
Hive.registerAdapter(TagAdapter());
|
||||
}
|
||||
if (!Hive.isAdapterRegistered(TransactionRecordAdapter().typeId)) {
|
||||
Hive.registerAdapter(TransactionRecordAdapter());
|
||||
}
|
||||
|
||||
await Hive.openBox<Category>(_categoryBox);
|
||||
await Hive.openBox<Tag>(_tagBox);
|
||||
await Hive.openBox<TransactionRecord>(_transactionBox);
|
||||
// Открытие всех Box'ов
|
||||
await Future.wait([
|
||||
Hive.openBox<Category>(_categoryBox),
|
||||
Hive.openBox<Tag>(_tagBox),
|
||||
Hive.openBox<TransactionRecord>(_transactionBox),
|
||||
]);
|
||||
}
|
||||
|
||||
static Box<Category> get categories => Hive.box<Category>(_categoryBox);
|
||||
|
||||
+6
-2
@@ -1,6 +1,10 @@
|
||||
/// Модель тега для дополнительной маркировки транзакций
|
||||
/// Позволяет добавлять дополнительные метки к операциям
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
part 'tag.g.dart';
|
||||
|
||||
@HiveType(typeId: 1)
|
||||
class Tag {
|
||||
@HiveField(0)
|
||||
/// Уникальный идентификатор тега
|
||||
final String id;
|
||||
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
part 'transaction_record.g.dart';
|
||||
|
||||
@HiveType(typeId: 2)
|
||||
import 'category.dart';
|
||||
import 'tag.dart';
|
||||
|
||||
@@ -7,6 +12,7 @@ import 'tag.dart';
|
||||
class TransactionRecord {
|
||||
|
||||
/// Уникальный идентификатор транзакции
|
||||
@HiveField(0)
|
||||
final String id;
|
||||
|
||||
/// Ссылка на категорию транзакции
|
||||
|
||||
Reference in New Issue
Block a user