This commit refactors the data repositories to remove user-specific filtering. It simplifies the data access logic by retrieving all data from the Hive boxes and removing the need to filter by `userId` in the repository methods. This change makes the app function in single-user mode and removes the need to manage multiple user contexts within the data layer. Specifically: - Removes `userId` parameter from repository methods. - Updates the setting repository to use fixed keys. - Removes user ID filtering from queries. - Removes user ID parameters from Cubits and Blocs - Updates initial data creation
86 lines
2.7 KiB
Dart
86 lines
2.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../models/category.dart';
|
|
|
|
/// Утилиты для работы с категориями
|
|
class CategoryUtils {
|
|
/// Возвращает список предопределенных категорий для конкретного пользователя
|
|
/// Включает как категории доходов, так и расходов
|
|
/// [userId] - идентификатор пользователя, для которого создаются категории
|
|
static List<Category> getDefaultCategories() {
|
|
return [
|
|
// Категории доходов
|
|
Category(
|
|
id: 'income_salary',
|
|
name: 'Зарплата',
|
|
color: Colors.green,
|
|
icon: Icons.attach_money,
|
|
isIncome: true,
|
|
),
|
|
Category(
|
|
id: 'income_gift',
|
|
name: 'Подарки',
|
|
color: Colors.blue,
|
|
icon: Icons.card_giftcard,
|
|
isIncome: true,
|
|
),
|
|
Category(
|
|
id: 'income_freelance',
|
|
name: 'Фриланс',
|
|
color: Colors.teal,
|
|
icon: Icons.computer,
|
|
isIncome: true,
|
|
),
|
|
|
|
// Категории расходов
|
|
Category(
|
|
id: 'expense_food',
|
|
name: 'Еда',
|
|
color: Colors.red,
|
|
icon: Icons.fastfood,
|
|
isIncome: false,
|
|
),
|
|
Category(
|
|
id: 'expense_transport',
|
|
name: 'Транспорт',
|
|
color: Colors.orange,
|
|
icon: Icons.directions_car,
|
|
isIncome: false,
|
|
),
|
|
Category(
|
|
id: 'expense_entertainment',
|
|
name: 'Развлечения',
|
|
color: Colors.purple,
|
|
icon: Icons.movie,
|
|
isIncome: false,
|
|
),
|
|
Category(
|
|
id: 'expense_utilities',
|
|
name: 'Коммунальные',
|
|
color: Colors.blueGrey,
|
|
icon: Icons.home,
|
|
isIncome: false,
|
|
),
|
|
Category(
|
|
id: 'expense_shopping',
|
|
name: 'Покупки',
|
|
color: Colors.pink,
|
|
icon: Icons.shopping_bag,
|
|
isIncome: false,
|
|
),
|
|
];
|
|
}
|
|
|
|
/// Возвращает только категории доходов для конкретного пользователя
|
|
/// [userId] - идентификатор пользователя
|
|
static List<Category> getIncomeCategories(String userId) {
|
|
return getDefaultCategories().where((c) => c.isIncome).toList();
|
|
}
|
|
|
|
/// Возвращает только категории расходов для конкретного пользователя
|
|
/// [userId] - идентификатор пользователя
|
|
static List<Category> getExpenseCategories(String userId) {
|
|
return getDefaultCategories().where((c) => !c.isIncome).toList();
|
|
}
|
|
}
|