Small fix
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:budget_app/models/category.dart';
|
||||
import 'package:budget_app/models/tag.dart';
|
||||
import 'package:budget_app/models/transaction_record.dart';
|
||||
|
||||
@GenerateAdapters([
|
||||
AdapterSpec<Category>(),
|
||||
AdapterSpec<Tag>(),
|
||||
AdapterSpec<TransactionRecord>(),
|
||||
])
|
||||
part 'hive_adapters.g.dart';
|
||||
@@ -0,0 +1,142 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'hive_adapters.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// AdaptersGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class CategoryAdapter extends TypeAdapter<Category> {
|
||||
@override
|
||||
final typeId = 0;
|
||||
|
||||
@override
|
||||
Category read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return Category(
|
||||
id: fields[0] as String?,
|
||||
name: fields[1] as String,
|
||||
color: fields[2] as Color,
|
||||
icon: fields[3] as IconData,
|
||||
isIncome: fields[4] as bool,
|
||||
userId: fields[5] as String,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, Category obj) {
|
||||
writer
|
||||
..writeByte(6)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
..write(obj.name)
|
||||
..writeByte(2)
|
||||
..write(obj.color)
|
||||
..writeByte(3)
|
||||
..write(obj.icon)
|
||||
..writeByte(4)
|
||||
..write(obj.isIncome)
|
||||
..writeByte(5)
|
||||
..write(obj.userId);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is CategoryAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
|
||||
class TagAdapter extends TypeAdapter<Tag> {
|
||||
@override
|
||||
final typeId = 1;
|
||||
|
||||
@override
|
||||
Tag read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return Tag(id: fields[0] as String?, name: fields[1] as String);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, Tag obj) {
|
||||
writer
|
||||
..writeByte(2)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
..write(obj.name);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is TagAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
|
||||
class TransactionRecordAdapter extends TypeAdapter<TransactionRecord> {
|
||||
@override
|
||||
final typeId = 2;
|
||||
|
||||
@override
|
||||
TransactionRecord read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return TransactionRecord(
|
||||
id: fields[0] as String?,
|
||||
category: fields[1] as Category,
|
||||
tag: fields[2] as Tag?,
|
||||
amount: (fields[3] as num).toDouble(),
|
||||
dateTime: fields[4] as DateTime,
|
||||
vendor: fields[5] as String,
|
||||
currency: fields[6] as String,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, TransactionRecord obj) {
|
||||
writer
|
||||
..writeByte(7)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
..write(obj.category)
|
||||
..writeByte(2)
|
||||
..write(obj.tag)
|
||||
..writeByte(3)
|
||||
..write(obj.amount)
|
||||
..writeByte(4)
|
||||
..write(obj.dateTime)
|
||||
..writeByte(5)
|
||||
..write(obj.vendor)
|
||||
..writeByte(6)
|
||||
..write(obj.currency);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is TransactionRecordAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
# Generated by Hive CE
|
||||
# Manual modifications may be necessary for certain migrations
|
||||
# Check in to version control
|
||||
nextTypeId: 3
|
||||
types:
|
||||
Category:
|
||||
typeId: 0
|
||||
nextIndex: 6
|
||||
fields:
|
||||
id:
|
||||
index: 0
|
||||
name:
|
||||
index: 1
|
||||
color:
|
||||
index: 2
|
||||
icon:
|
||||
index: 3
|
||||
isIncome:
|
||||
index: 4
|
||||
userId:
|
||||
index: 5
|
||||
Tag:
|
||||
typeId: 1
|
||||
nextIndex: 2
|
||||
fields:
|
||||
id:
|
||||
index: 0
|
||||
name:
|
||||
index: 1
|
||||
TransactionRecord:
|
||||
typeId: 2
|
||||
nextIndex: 7
|
||||
fields:
|
||||
id:
|
||||
index: 0
|
||||
category:
|
||||
index: 1
|
||||
tag:
|
||||
index: 2
|
||||
amount:
|
||||
index: 3
|
||||
dateTime:
|
||||
index: 4
|
||||
vendor:
|
||||
index: 5
|
||||
currency:
|
||||
index: 6
|
||||
@@ -0,0 +1,34 @@
|
||||
// Generated by Hive CE
|
||||
// Do not modify
|
||||
// Check in to version control
|
||||
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:budget_app/hive/hive_adapters.dart';
|
||||
import 'package:budget_app/models/category.dart' hide CategoryAdapter;
|
||||
import 'package:budget_app/models/tag.dart' hide TagAdapter;
|
||||
import 'package:budget_app/models/transaction_record.dart' hide TransactionRecordAdapter;
|
||||
import 'package:budget_app/models/user.dart';
|
||||
|
||||
extension HiveRegistrar on HiveInterface {
|
||||
void registerAdapters() {
|
||||
registerAdapter(CategoryAdapter());
|
||||
registerAdapter(CategoryAdapter());
|
||||
registerAdapter(TagAdapter());
|
||||
registerAdapter(TagAdapter());
|
||||
registerAdapter(TransactionRecordAdapter());
|
||||
registerAdapter(TransactionRecordAdapter());
|
||||
registerAdapter(UserAdapter());
|
||||
}
|
||||
}
|
||||
|
||||
extension IsolatedHiveRegistrar on IsolatedHiveInterface {
|
||||
void registerAdapters() {
|
||||
registerAdapter(CategoryAdapter());
|
||||
registerAdapter(CategoryAdapter());
|
||||
registerAdapter(TagAdapter());
|
||||
registerAdapter(TagAdapter());
|
||||
registerAdapter(TransactionRecordAdapter());
|
||||
registerAdapter(TransactionRecordAdapter());
|
||||
registerAdapter(UserAdapter());
|
||||
}
|
||||
}
|
||||
@@ -22,13 +22,14 @@ class CategoryAdapter extends TypeAdapter<Category> {
|
||||
color: fields[2] as Color,
|
||||
icon: fields[3] as IconData,
|
||||
isIncome: fields[4] as bool,
|
||||
userId: fields[5] as String,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, Category obj) {
|
||||
writer
|
||||
..writeByte(5)
|
||||
..writeByte(6)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
@@ -38,7 +39,9 @@ class CategoryAdapter extends TypeAdapter<Category> {
|
||||
..writeByte(3)
|
||||
..write(obj.icon)
|
||||
..writeByte(4)
|
||||
..write(obj.isIncome);
|
||||
..write(obj.isIncome)
|
||||
..writeByte(5)
|
||||
..write(obj.userId);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'user.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class UserAdapter extends TypeAdapter<User> {
|
||||
@override
|
||||
final typeId = 3;
|
||||
|
||||
@override
|
||||
User read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return User(
|
||||
id: fields[0] as String?,
|
||||
name: fields[1] as String,
|
||||
email: fields[2] as String,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, User obj) {
|
||||
writer
|
||||
..writeByte(3)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
..write(obj.name)
|
||||
..writeByte(2)
|
||||
..write(obj.email);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is UserAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
@@ -7,8 +7,8 @@ import 'tag_utils.dart';
|
||||
/// Утилиты для работы с тестовыми транзакциями
|
||||
class TransactionUtils {
|
||||
/// Возвращает список тестовых транзакций
|
||||
static List<TransactionRecord> getSampleTransactions() {
|
||||
final categories = CategoryUtils.getDefaultCategories();
|
||||
static List<TransactionRecord> getSampleTransactions(String userId) {
|
||||
final categories = CategoryUtils.getDefaultCategories(userId);
|
||||
final tags = TagUtils.getDefaultTags();
|
||||
|
||||
return [
|
||||
@@ -56,14 +56,4 @@ class TransactionUtils {
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/// Возвращает только доходы
|
||||
static List<TransactionRecord> getIncomeTransactions() {
|
||||
return getSampleTransactions().where((t) => t.isIncome).toList();
|
||||
}
|
||||
|
||||
/// Возвращает только расходы
|
||||
static List<TransactionRecord> getExpenseTransactions() {
|
||||
return getSampleTransactions().where((t) => !t.isIncome).toList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user