Initial commit: SubManager Flutter App
주요 구현 완료 기능: - 구독 관리 (추가/편집/삭제/카테고리 분류) - 이벤트 할인 시스템 (기본값 자동 설정) - SMS 자동 스캔 및 구독 정보 추출 - 알림 시스템 (타임존 처리 안정화) - 환율 변환 지원 (KRW/USD) - 반응형 UI 및 애니메이션 - 다국어 지원 (한국어/영어) 버그 수정: - NotificationService tz.local 초기화 오류 해결 - MainScreenSummaryCard 레이아웃 오버플로우 수정 - 구독 추가 시 LateInitializationError 완전 해결 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
86
lib/providers/category_provider.dart
Normal file
86
lib/providers/category_provider.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import '../models/category_model.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class CategoryProvider extends ChangeNotifier {
|
||||
List<CategoryModel> _categories = [];
|
||||
late Box<CategoryModel> _categoryBox;
|
||||
|
||||
List<CategoryModel> get categories => _categories;
|
||||
|
||||
Future<void> init() async {
|
||||
_categoryBox = await Hive.openBox<CategoryModel>('categories');
|
||||
_categories = _categoryBox.values.toList();
|
||||
|
||||
// 카테고리가 비어있으면 기본 카테고리 추가
|
||||
if (_categories.isEmpty) {
|
||||
await _initDefaultCategories();
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// 기본 카테고리 초기화
|
||||
Future<void> _initDefaultCategories() async {
|
||||
final defaultCategories = [
|
||||
{'name': 'OTT 서비스', 'color': '#3B82F6', 'icon': 'live_tv'},
|
||||
{'name': '음악 서비스', 'color': '#EC4899', 'icon': 'music_note'},
|
||||
{'name': 'AI 서비스', 'color': '#8B5CF6', 'icon': 'psychology'},
|
||||
{'name': '프로그래밍/개발', 'color': '#10B981', 'icon': 'code'},
|
||||
{'name': '오피스/협업 툴', 'color': '#F59E0B', 'icon': 'business_center'},
|
||||
{'name': '기타 서비스', 'color': '#6B7280', 'icon': 'more_horiz'},
|
||||
];
|
||||
|
||||
for (final category in defaultCategories) {
|
||||
final newCategory = CategoryModel(
|
||||
id: const Uuid().v4(),
|
||||
name: category['name']!,
|
||||
color: category['color']!,
|
||||
icon: category['icon']!,
|
||||
);
|
||||
|
||||
await _categoryBox.put(newCategory.id, newCategory);
|
||||
_categories.add(newCategory);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addCategory({
|
||||
required String name,
|
||||
required String color,
|
||||
required String icon,
|
||||
}) async {
|
||||
final newCategory = CategoryModel(
|
||||
id: const Uuid().v4(),
|
||||
name: name,
|
||||
color: color,
|
||||
icon: icon,
|
||||
);
|
||||
await _categoryBox.put(newCategory.id, newCategory);
|
||||
_categories.add(newCategory);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> updateCategory(CategoryModel updated) async {
|
||||
await _categoryBox.put(updated.id, updated);
|
||||
int index = _categories.indexWhere((cat) => cat.id == updated.id);
|
||||
if (index != -1) {
|
||||
_categories[index] = updated;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteCategory(String id) async {
|
||||
await _categoryBox.delete(id);
|
||||
_categories.removeWhere((cat) => cat.id == id);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
CategoryModel? getCategoryById(String id) {
|
||||
try {
|
||||
return _categories.firstWhere((cat) => cat.id == id);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user