style: apply dart format across project
This commit is contained in:
@@ -19,9 +19,9 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
|
||||
double get totalMonthlyExpense {
|
||||
final exchangeRateService = ExchangeRateService();
|
||||
final rate = exchangeRateService.cachedUsdToKrwRate ??
|
||||
ExchangeRateService.DEFAULT_USD_TO_KRW_RATE;
|
||||
|
||||
final rate = exchangeRateService.cachedUsdToKrwRate ??
|
||||
ExchangeRateService.DEFAULT_USD_TO_KRW_RATE;
|
||||
|
||||
final total = _subscriptions.fold(
|
||||
0.0,
|
||||
(sum, subscription) {
|
||||
@@ -31,11 +31,12 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
'\$${price} × ₩$rate = ₩${price * rate}');
|
||||
return sum + (price * rate);
|
||||
}
|
||||
debugPrint('[SubscriptionProvider] ${subscription.serviceName}: ₩$price');
|
||||
debugPrint(
|
||||
'[SubscriptionProvider] ${subscription.serviceName}: ₩$price');
|
||||
return sum + price;
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
debugPrint('[SubscriptionProvider] totalMonthlyExpense 계산 완료: '
|
||||
'${_subscriptions.length}개 구독, 총액 ₩$total');
|
||||
return total;
|
||||
@@ -69,10 +70,10 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
|
||||
_subscriptionBox = await Hive.openBox<SubscriptionModel>('subscriptions');
|
||||
await refreshSubscriptions();
|
||||
|
||||
|
||||
// categoryId 마이그레이션
|
||||
await _migrateCategoryIds();
|
||||
|
||||
|
||||
// 앱 시작 시 이벤트 상태 확인
|
||||
await checkAndUpdateEventStatus();
|
||||
|
||||
@@ -90,11 +91,11 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
try {
|
||||
_subscriptions = _subscriptionBox.values.toList()
|
||||
..sort((a, b) => a.nextBillingDate.compareTo(b.nextBillingDate));
|
||||
|
||||
|
||||
debugPrint('[SubscriptionProvider] refreshSubscriptions 완료: '
|
||||
'${_subscriptions.length}개 구독, '
|
||||
'총 월간 지출: ${totalMonthlyExpense.toStringAsFixed(2)}');
|
||||
|
||||
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
debugPrint('구독 목록 새로고침 중 오류 발생: $e');
|
||||
@@ -139,7 +140,7 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
|
||||
await _subscriptionBox.put(subscription.id, subscription);
|
||||
await refreshSubscriptions();
|
||||
|
||||
|
||||
// 이벤트가 활성화된 경우 알림 스케줄 재설정
|
||||
if (isEventActive && eventEndDate != null) {
|
||||
await _scheduleEventEndNotification(subscription);
|
||||
@@ -191,7 +192,6 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Future<void> clearAllSubscriptions() async {
|
||||
_isLoading = true;
|
||||
notifyListeners();
|
||||
@@ -217,8 +217,9 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
/// 이벤트 종료 알림을 스케줄링합니다.
|
||||
Future<void> _scheduleEventEndNotification(SubscriptionModel subscription) async {
|
||||
if (subscription.eventEndDate != null &&
|
||||
Future<void> _scheduleEventEndNotification(
|
||||
SubscriptionModel subscription) async {
|
||||
if (subscription.eventEndDate != null &&
|
||||
subscription.eventEndDate!.isAfter(DateTime.now())) {
|
||||
await NotificationService.scheduleNotification(
|
||||
id: '${subscription.id}_event_end'.hashCode,
|
||||
@@ -232,19 +233,18 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
/// 모든 구독의 이벤트 상태를 확인하고 업데이트합니다.
|
||||
Future<void> checkAndUpdateEventStatus() async {
|
||||
bool hasChanges = false;
|
||||
|
||||
|
||||
for (var subscription in _subscriptions) {
|
||||
// 이벤트가 종료되었지만 아직 활성화되어 있는 경우
|
||||
if (subscription.isEventActive &&
|
||||
if (subscription.isEventActive &&
|
||||
subscription.eventEndDate != null &&
|
||||
subscription.eventEndDate!.isBefore(DateTime.now())) {
|
||||
|
||||
subscription.isEventActive = false;
|
||||
await _subscriptionBox.put(subscription.id, subscription);
|
||||
hasChanges = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (hasChanges) {
|
||||
await refreshSubscriptions();
|
||||
}
|
||||
@@ -253,70 +253,73 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
/// 총 월간 지출을 계산합니다. (로케일별 기본 통화로 환산)
|
||||
Future<double> calculateTotalExpense({String? locale}) async {
|
||||
if (_subscriptions.isEmpty) return 0.0;
|
||||
|
||||
|
||||
// locale이 제공되지 않으면 현재 로케일 사용
|
||||
final targetCurrency = locale != null
|
||||
? CurrencyUtil.getDefaultCurrency(locale)
|
||||
: 'KRW'; // 기본값
|
||||
|
||||
final targetCurrency =
|
||||
locale != null ? CurrencyUtil.getDefaultCurrency(locale) : 'KRW'; // 기본값
|
||||
|
||||
debugPrint('[calculateTotalExpense] 계산 시작 - 타겟 통화: $targetCurrency');
|
||||
double total = 0.0;
|
||||
|
||||
|
||||
for (final subscription in _subscriptions) {
|
||||
final currentPrice = subscription.currentPrice;
|
||||
debugPrint('[calculateTotalExpense] ${subscription.serviceName}: '
|
||||
'${currentPrice} ${subscription.currency} (이벤트 적용: ${subscription.isCurrentlyInEvent})');
|
||||
|
||||
|
||||
final converted = await ExchangeRateService().convertBetweenCurrencies(
|
||||
currentPrice,
|
||||
subscription.currency,
|
||||
targetCurrency,
|
||||
);
|
||||
|
||||
|
||||
total += converted ?? currentPrice;
|
||||
}
|
||||
|
||||
|
||||
debugPrint('[calculateTotalExpense] 총 지출 계산 완료: $total $targetCurrency');
|
||||
return total;
|
||||
}
|
||||
|
||||
/// 최근 6개월의 월별 지출 데이터를 반환합니다. (로케일별 기본 통화로 환산)
|
||||
Future<List<Map<String, dynamic>>> getMonthlyExpenseData({String? locale}) async {
|
||||
Future<List<Map<String, dynamic>>> getMonthlyExpenseData(
|
||||
{String? locale}) async {
|
||||
final now = DateTime.now();
|
||||
final List<Map<String, dynamic>> monthlyData = [];
|
||||
|
||||
|
||||
// locale이 제공되지 않으면 현재 로케일 사용
|
||||
final targetCurrency = locale != null
|
||||
? CurrencyUtil.getDefaultCurrency(locale)
|
||||
: 'KRW'; // 기본값
|
||||
|
||||
final targetCurrency =
|
||||
locale != null ? CurrencyUtil.getDefaultCurrency(locale) : 'KRW'; // 기본값
|
||||
|
||||
// 최근 6개월 데이터 생성
|
||||
for (int i = 5; i >= 0; i--) {
|
||||
final month = DateTime(now.year, now.month - i, 1);
|
||||
double monthTotal = 0.0;
|
||||
|
||||
|
||||
// 현재 월인지 확인
|
||||
final isCurrentMonth = (month.year == now.year && month.month == now.month);
|
||||
|
||||
final isCurrentMonth =
|
||||
(month.year == now.year && month.month == now.month);
|
||||
|
||||
if (isCurrentMonth) {
|
||||
debugPrint('[getMonthlyExpenseData] 현재 월(${month.year}-${month.month}) 계산 중...');
|
||||
debugPrint(
|
||||
'[getMonthlyExpenseData] 현재 월(${month.year}-${month.month}) 계산 중...');
|
||||
}
|
||||
|
||||
|
||||
// 해당 월에 활성화된 구독 계산
|
||||
for (final subscription in _subscriptions) {
|
||||
if (isCurrentMonth) {
|
||||
// 현재 월인 경우: 모든 활성 구독 포함 (calculateTotalExpense와 동일하게)
|
||||
final cost = subscription.currentPrice;
|
||||
debugPrint('[getMonthlyExpenseData] 현재 월 - ${subscription.serviceName}: '
|
||||
debugPrint(
|
||||
'[getMonthlyExpenseData] 현재 월 - ${subscription.serviceName}: '
|
||||
'${cost} ${subscription.currency} (이벤트 적용: ${subscription.isCurrentlyInEvent})');
|
||||
|
||||
|
||||
// 통화 변환
|
||||
final converted = await ExchangeRateService().convertBetweenCurrencies(
|
||||
final converted =
|
||||
await ExchangeRateService().convertBetweenCurrencies(
|
||||
cost,
|
||||
subscription.currency,
|
||||
targetCurrency,
|
||||
);
|
||||
|
||||
|
||||
monthTotal += converted ?? cost;
|
||||
} else {
|
||||
// 과거 월인 경우: 기존 로직 유지
|
||||
@@ -324,46 +327,50 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
final subscriptionStartDate = subscription.nextBillingDate.subtract(
|
||||
Duration(days: _getBillingCycleDays(subscription.billingCycle)),
|
||||
);
|
||||
|
||||
if (subscriptionStartDate.isBefore(DateTime(month.year, month.month + 1, 1)) &&
|
||||
|
||||
if (subscriptionStartDate
|
||||
.isBefore(DateTime(month.year, month.month + 1, 1)) &&
|
||||
subscription.nextBillingDate.isAfter(month)) {
|
||||
// 해당 월의 비용 계산 (이벤트 가격 고려)
|
||||
double cost;
|
||||
|
||||
if (subscription.isEventActive &&
|
||||
|
||||
if (subscription.isEventActive &&
|
||||
subscription.eventStartDate != null &&
|
||||
subscription.eventEndDate != null &&
|
||||
// 이벤트 기간과 해당 월이 겹치는지 확인
|
||||
subscription.eventStartDate!.isBefore(DateTime(month.year, month.month + 1, 1)) &&
|
||||
subscription.eventStartDate!
|
||||
.isBefore(DateTime(month.year, month.month + 1, 1)) &&
|
||||
subscription.eventEndDate!.isAfter(month)) {
|
||||
cost = subscription.eventPrice ?? subscription.monthlyCost;
|
||||
} else {
|
||||
cost = subscription.monthlyCost;
|
||||
}
|
||||
|
||||
|
||||
// 통화 변환
|
||||
final converted = await ExchangeRateService().convertBetweenCurrencies(
|
||||
final converted =
|
||||
await ExchangeRateService().convertBetweenCurrencies(
|
||||
cost,
|
||||
subscription.currency,
|
||||
targetCurrency,
|
||||
);
|
||||
|
||||
|
||||
monthTotal += converted ?? cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isCurrentMonth) {
|
||||
debugPrint('[getMonthlyExpenseData] 현재 월(${_getMonthLabel(month, locale ?? 'en')}) 총 지출: $monthTotal $targetCurrency');
|
||||
debugPrint(
|
||||
'[getMonthlyExpenseData] 현재 월(${_getMonthLabel(month, locale ?? 'en')}) 총 지출: $monthTotal $targetCurrency');
|
||||
}
|
||||
|
||||
|
||||
monthlyData.add({
|
||||
'month': month,
|
||||
'totalExpense': monthTotal,
|
||||
'monthName': _getMonthLabel(month, locale ?? 'en'),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
return monthlyData;
|
||||
}
|
||||
|
||||
@@ -409,96 +416,109 @@ class SubscriptionProvider extends ChangeNotifier {
|
||||
/// categoryId가 없는 기존 구독들에 대해 자동으로 카테고리 할당
|
||||
Future<void> _migrateCategoryIds() async {
|
||||
debugPrint('❎ CategoryId 마이그레이션 시작...');
|
||||
|
||||
|
||||
final categoryProvider = CategoryProvider();
|
||||
await categoryProvider.init();
|
||||
final categories = categoryProvider.categories;
|
||||
|
||||
|
||||
int migratedCount = 0;
|
||||
|
||||
|
||||
for (var subscription in _subscriptions) {
|
||||
if (subscription.categoryId == null) {
|
||||
final serviceName = subscription.serviceName.toLowerCase();
|
||||
String? categoryId;
|
||||
|
||||
|
||||
debugPrint('🔍 ${subscription.serviceName} 카테고리 매칭 시도...');
|
||||
|
||||
|
||||
// OTT 서비스
|
||||
if (serviceName.contains('netflix') ||
|
||||
serviceName.contains('youtube') ||
|
||||
if (serviceName.contains('netflix') ||
|
||||
serviceName.contains('youtube') ||
|
||||
serviceName.contains('disney') ||
|
||||
serviceName.contains('왓차') ||
|
||||
serviceName.contains('티빙') ||
|
||||
serviceName.contains('디즈니') ||
|
||||
serviceName.contains('넷플릭스')) {
|
||||
categoryId = categories.firstWhere(
|
||||
(cat) => cat.name == 'OTT 서비스',
|
||||
orElse: () => categories.first,
|
||||
).id;
|
||||
categoryId = categories
|
||||
.firstWhere(
|
||||
(cat) => cat.name == 'OTT 서비스',
|
||||
orElse: () => categories.first,
|
||||
)
|
||||
.id;
|
||||
}
|
||||
// 음악 서비스
|
||||
else if (serviceName.contains('spotify') ||
|
||||
serviceName.contains('apple music') ||
|
||||
serviceName.contains('멜론') ||
|
||||
serviceName.contains('지니') ||
|
||||
serviceName.contains('플로') ||
|
||||
serviceName.contains('벡스')) {
|
||||
categoryId = categories.firstWhere(
|
||||
(cat) => cat.name == 'music',
|
||||
orElse: () => categories.first,
|
||||
).id;
|
||||
else if (serviceName.contains('spotify') ||
|
||||
serviceName.contains('apple music') ||
|
||||
serviceName.contains('멜론') ||
|
||||
serviceName.contains('지니') ||
|
||||
serviceName.contains('플로') ||
|
||||
serviceName.contains('벡스')) {
|
||||
categoryId = categories
|
||||
.firstWhere(
|
||||
(cat) => cat.name == 'music',
|
||||
orElse: () => categories.first,
|
||||
)
|
||||
.id;
|
||||
}
|
||||
// AI 서비스
|
||||
else if (serviceName.contains('chatgpt') ||
|
||||
serviceName.contains('claude') ||
|
||||
serviceName.contains('midjourney') ||
|
||||
serviceName.contains('copilot')) {
|
||||
categoryId = categories.firstWhere(
|
||||
(cat) => cat.name == 'aiService',
|
||||
orElse: () => categories.first,
|
||||
).id;
|
||||
else if (serviceName.contains('chatgpt') ||
|
||||
serviceName.contains('claude') ||
|
||||
serviceName.contains('midjourney') ||
|
||||
serviceName.contains('copilot')) {
|
||||
categoryId = categories
|
||||
.firstWhere(
|
||||
(cat) => cat.name == 'aiService',
|
||||
orElse: () => categories.first,
|
||||
)
|
||||
.id;
|
||||
}
|
||||
// 프로그래밍/개발
|
||||
else if (serviceName.contains('github') ||
|
||||
serviceName.contains('intellij') ||
|
||||
serviceName.contains('webstorm') ||
|
||||
serviceName.contains('jetbrains')) {
|
||||
categoryId = categories.firstWhere(
|
||||
(cat) => cat.name == 'programming',
|
||||
orElse: () => categories.first,
|
||||
).id;
|
||||
else if (serviceName.contains('github') ||
|
||||
serviceName.contains('intellij') ||
|
||||
serviceName.contains('webstorm') ||
|
||||
serviceName.contains('jetbrains')) {
|
||||
categoryId = categories
|
||||
.firstWhere(
|
||||
(cat) => cat.name == 'programming',
|
||||
orElse: () => categories.first,
|
||||
)
|
||||
.id;
|
||||
}
|
||||
// 오피스/협업 툴
|
||||
else if (serviceName.contains('notion') ||
|
||||
serviceName.contains('microsoft') ||
|
||||
serviceName.contains('office') ||
|
||||
serviceName.contains('slack') ||
|
||||
serviceName.contains('figma') ||
|
||||
serviceName.contains('icloud') ||
|
||||
serviceName.contains('아이클라우드')) {
|
||||
categoryId = categories.firstWhere(
|
||||
(cat) => cat.name == 'collaborationOffice',
|
||||
orElse: () => categories.first,
|
||||
).id;
|
||||
else if (serviceName.contains('notion') ||
|
||||
serviceName.contains('microsoft') ||
|
||||
serviceName.contains('office') ||
|
||||
serviceName.contains('slack') ||
|
||||
serviceName.contains('figma') ||
|
||||
serviceName.contains('icloud') ||
|
||||
serviceName.contains('아이클라우드')) {
|
||||
categoryId = categories
|
||||
.firstWhere(
|
||||
(cat) => cat.name == 'collaborationOffice',
|
||||
orElse: () => categories.first,
|
||||
)
|
||||
.id;
|
||||
}
|
||||
// 기타 서비스 (기본값)
|
||||
else {
|
||||
categoryId = categories.firstWhere(
|
||||
(cat) => cat.name == 'other',
|
||||
orElse: () => categories.first,
|
||||
).id;
|
||||
categoryId = categories
|
||||
.firstWhere(
|
||||
(cat) => cat.name == 'other',
|
||||
orElse: () => categories.first,
|
||||
)
|
||||
.id;
|
||||
}
|
||||
|
||||
|
||||
if (categoryId != null) {
|
||||
subscription.categoryId = categoryId;
|
||||
await subscription.save();
|
||||
migratedCount++;
|
||||
final categoryName = categories.firstWhere((cat) => cat.id == categoryId).name;
|
||||
final categoryName =
|
||||
categories.firstWhere((cat) => cat.id == categoryId).name;
|
||||
debugPrint('✅ ${subscription.serviceName} → $categoryName');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (migratedCount > 0) {
|
||||
debugPrint('❎ 총 ${migratedCount}개의 구독에 categoryId 할당 완료');
|
||||
await refreshSubscriptions();
|
||||
|
||||
Reference in New Issue
Block a user