feat: добавить автогенерацию ID через UUID
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import '../../utils/id_generator.dart';
|
||||
|
||||
part 'category.g.dart';
|
||||
|
||||
@@ -32,12 +33,12 @@ class Category {
|
||||
|
||||
/// Конструктор с обязательными параметрами
|
||||
const Category({
|
||||
required this.id,
|
||||
String? id,
|
||||
required this.name,
|
||||
required this.color,
|
||||
required this.icon,
|
||||
required this.isIncome,
|
||||
});
|
||||
}) : id = id ?? IdGenerator.generateId();
|
||||
|
||||
/// Метод для преобразования объекта в Map (полезно для работы с БД)
|
||||
Map<String, dynamic> toMap() {
|
||||
|
||||
+3
-2
@@ -1,4 +1,5 @@
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import '../../utils/id_generator.dart';
|
||||
|
||||
part 'tag.g.dart';
|
||||
|
||||
@@ -14,9 +15,9 @@ class Tag {
|
||||
|
||||
/// Конструктор с обязательными параметрами
|
||||
const Tag({
|
||||
required this.id,
|
||||
String? id,
|
||||
required this.name,
|
||||
});
|
||||
}) : id = id ?? IdGenerator.generateId();
|
||||
|
||||
/// Преобразование объекта в Map
|
||||
Map<String, dynamic> toMap() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import '../../utils/id_generator.dart';
|
||||
import 'category.dart';
|
||||
import 'tag.dart';
|
||||
|
||||
@@ -40,14 +41,14 @@ class TransactionRecord {
|
||||
|
||||
/// Конструктор с обязательными параметрами
|
||||
const TransactionRecord({
|
||||
required this.id,
|
||||
String? id,
|
||||
required this.category,
|
||||
this.tag,
|
||||
required this.amount,
|
||||
required this.dateTime,
|
||||
required this.vendor,
|
||||
required this.currency,
|
||||
});
|
||||
}) : id = id ?? IdGenerator.generateId();
|
||||
|
||||
/// Преобразование объекта в Map
|
||||
Map<String, dynamic> toMap() {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class IdGenerator {
|
||||
static final Uuid _uuid = Uuid();
|
||||
|
||||
/// Генерирует уникальный строковый ID
|
||||
static String generateId() {
|
||||
return _uuid.v4();
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ dependencies:
|
||||
hive_ce_flutter: ^2.3.1
|
||||
get_it: ^7.2.0
|
||||
path_provider: ^2.0.15
|
||||
uuid: ^3.0.7
|
||||
|
||||
dev_dependencies:
|
||||
hive_ce_generator: ^1.9.2
|
||||
|
||||
Reference in New Issue
Block a user