feat: 다국어 지원 및 다중 통화 환율 변환 기능 확대
- ExchangeRateService에 JPY, CNY 환율 지원 추가 - 구독 서비스별 다국어 표시 이름 지원 - 분석 화면 차트 및 UI/UX 개선 - 설정 화면 전면 리팩토링 - SMS 스캔 기능 사용성 개선 - 전체 앱 다국어 번역 확대 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,72 +1,175 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../models/subscription_model.dart';
|
||||
import '../../services/currency_util.dart';
|
||||
import '../../services/exchange_rate_service.dart';
|
||||
import '../../theme/app_colors.dart';
|
||||
import '../glassmorphism_card.dart';
|
||||
import '../themed_text.dart';
|
||||
import 'analysis_badge.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../../providers/locale_provider.dart';
|
||||
|
||||
/// 구독 서비스 비율을 파이 차트로 보여주는 카드 위젯
|
||||
class SubscriptionPieChartCard extends StatelessWidget {
|
||||
class SubscriptionPieChartCard extends StatefulWidget {
|
||||
final List<SubscriptionModel> subscriptions;
|
||||
final AnimationController animationController;
|
||||
final int touchedIndex;
|
||||
final Function(int) onPieTouch;
|
||||
|
||||
const SubscriptionPieChartCard({
|
||||
super.key,
|
||||
required this.subscriptions,
|
||||
required this.animationController,
|
||||
required this.touchedIndex,
|
||||
required this.onPieTouch,
|
||||
});
|
||||
|
||||
// 파이 차트 섹션 데이터
|
||||
List<PieChartSectionData> _getPieSections() {
|
||||
if (subscriptions.isEmpty) return [];
|
||||
@override
|
||||
State<SubscriptionPieChartCard> createState() => _SubscriptionPieChartCardState();
|
||||
}
|
||||
|
||||
final colors = [
|
||||
const Color(0xFF3B82F6),
|
||||
const Color(0xFF10B981),
|
||||
const Color(0xFFF59E0B),
|
||||
const Color(0xFFEF4444),
|
||||
const Color(0xFF8B5CF6),
|
||||
const Color(0xFF0EA5E9),
|
||||
const Color(0xFFEC4899),
|
||||
];
|
||||
class _SubscriptionPieChartCardState extends State<SubscriptionPieChartCard> {
|
||||
int _touchedIndex = -1;
|
||||
late Future<List<PieChartSectionData>> _pieSectionsFuture;
|
||||
String? _lastLocale;
|
||||
|
||||
static const _chartColors = [
|
||||
Color(0xFF3B82F6),
|
||||
Color(0xFF10B981),
|
||||
Color(0xFFF59E0B),
|
||||
Color(0xFFEF4444),
|
||||
Color(0xFF8B5CF6),
|
||||
Color(0xFF0EA5E9),
|
||||
Color(0xFFEC4899),
|
||||
];
|
||||
|
||||
// 개별 구독의 비율 계산을 위한 값들
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_initializeFuture();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(SubscriptionPieChartCard oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
// subscriptions나 locale이 변경된 경우만 Future 재생성
|
||||
final currentLocale = context.read<LocaleProvider>().locale.languageCode;
|
||||
if (!_listEquals(oldWidget.subscriptions, widget.subscriptions) ||
|
||||
_lastLocale != currentLocale) {
|
||||
_initializeFuture();
|
||||
}
|
||||
}
|
||||
|
||||
void _initializeFuture() {
|
||||
_lastLocale = context.read<LocaleProvider>().locale.languageCode;
|
||||
_pieSectionsFuture = _getPieSections();
|
||||
}
|
||||
|
||||
bool _listEquals(List<SubscriptionModel> a, List<SubscriptionModel> b) {
|
||||
if (a.length != b.length) return false;
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
if (a[i].id != b[i].id ||
|
||||
a[i].currentPrice != b[i].currentPrice ||
|
||||
a[i].currency != b[i].currency ||
|
||||
a[i].serviceName != b[i].serviceName) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 파이 차트 섹션 데이터 (언어별 기본 통화로 환산)
|
||||
Future<List<PieChartSectionData>> _getPieSections() async {
|
||||
|
||||
if (widget.subscriptions.isEmpty) return [];
|
||||
|
||||
// 현재 locale 가져오기
|
||||
final locale = context.read<LocaleProvider>().locale.languageCode;
|
||||
final defaultCurrency = CurrencyUtil.getDefaultCurrency(locale);
|
||||
|
||||
// 개별 구독의 비율 계산을 위한 값들 (기본 통화로 환산)
|
||||
List<double> sectionValues = [];
|
||||
|
||||
// 각 구독의 원화 환산 금액 또는 원화 금액을 계산
|
||||
for (var subscription in subscriptions) {
|
||||
double value = subscription.monthlyCost;
|
||||
if (subscription.currency == 'USD') {
|
||||
// USD의 경우 마지막으로 조회된 환율로 대략적인 계산
|
||||
// (정확한 계산은 비동기로 이루어지므로 UI 표시용으로만 사용)
|
||||
const rate = 1350.0; // 기본 환율 (실제 값은 API로 별도로 가져옴)
|
||||
value = value * rate;
|
||||
// 각 구독의 현재 가격을 언어별 기본 통화로 환산
|
||||
for (var subscription in widget.subscriptions) {
|
||||
double value = subscription.currentPrice;
|
||||
|
||||
if (subscription.currency == defaultCurrency) {
|
||||
// 이미 기본 통화인 경우 그대로 사용
|
||||
sectionValues.add(value);
|
||||
} else if (subscription.currency == 'USD') {
|
||||
// USD를 기본 통화로 변환
|
||||
final converted = await ExchangeRateService().convertUsdToTarget(value, defaultCurrency);
|
||||
sectionValues.add(converted ?? value);
|
||||
} else if (defaultCurrency == 'USD') {
|
||||
// 기본 통화가 USD인 경우 다른 통화를 USD로 변환
|
||||
final converted = await ExchangeRateService().convertTargetToUsd(value, subscription.currency);
|
||||
sectionValues.add(converted ?? value);
|
||||
} else {
|
||||
// 기타 통화는 일단 그대로 사용 (환율 정보가 없는 경우)
|
||||
sectionValues.add(value);
|
||||
}
|
||||
sectionValues.add(value);
|
||||
}
|
||||
|
||||
// 총합 계산
|
||||
double sectionsTotal = sectionValues.fold(0, (sum, value) => sum + value);
|
||||
|
||||
// 총합이 0이면 빈 배열 반환
|
||||
if (sectionsTotal == 0) return [];
|
||||
|
||||
// 섹션 데이터 생성
|
||||
return List.generate(subscriptions.length, (i) {
|
||||
final subscription = subscriptions[i];
|
||||
// 섹션 데이터 생성 (터치 상태 제외)
|
||||
final sections = List.generate(widget.subscriptions.length, (i) {
|
||||
final percentage = (sectionValues[i] / sectionsTotal) * 100;
|
||||
final index = i % colors.length;
|
||||
final isTouched = touchedIndex == i;
|
||||
final fontSize = isTouched ? 16.0 : 12.0;
|
||||
final radius = isTouched ? 105.0 : 100.0;
|
||||
final index = i % _chartColors.length;
|
||||
|
||||
return PieChartSectionData(
|
||||
value: sectionValues[i],
|
||||
title: '${percentage.toStringAsFixed(1)}%',
|
||||
titleStyle: TextStyle(
|
||||
titleStyle: const TextStyle(
|
||||
fontSize: 12.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.pureWhite,
|
||||
shadows: [
|
||||
Shadow(color: Colors.black26, blurRadius: 2, offset: Offset(0, 1))
|
||||
],
|
||||
),
|
||||
color: _chartColors[index],
|
||||
radius: 100.0,
|
||||
titlePositionPercentageOffset: 0.6,
|
||||
badgeWidget: null,
|
||||
badgePositionPercentageOffset: .98,
|
||||
);
|
||||
});
|
||||
|
||||
return sections;
|
||||
}
|
||||
|
||||
// 배지 위젯 생성
|
||||
Widget _createBadgeWidget(int index) {
|
||||
if (index >= widget.subscriptions.length) return const SizedBox.shrink();
|
||||
|
||||
final subscription = widget.subscriptions[index];
|
||||
final colorIndex = index % _chartColors.length;
|
||||
|
||||
return IgnorePointer(
|
||||
child: AnalysisBadge(
|
||||
size: 40,
|
||||
borderColor: _chartColors[colorIndex],
|
||||
subscription: subscription,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 터치 상태를 반영한 섹션 데이터 생성
|
||||
List<PieChartSectionData> _applyTouchedState(List<PieChartSectionData> sections) {
|
||||
return List.generate(sections.length, (i) {
|
||||
final section = sections[i];
|
||||
final isTouched = _touchedIndex == i;
|
||||
final fontSize = isTouched ? 16.0 : 12.0;
|
||||
final radius = isTouched ? 105.0 : 100.0;
|
||||
|
||||
return PieChartSectionData(
|
||||
value: section.value,
|
||||
title: section.title,
|
||||
titleStyle: section.titleStyle?.copyWith(fontSize: fontSize) ?? TextStyle(
|
||||
fontSize: fontSize,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.pureWhite,
|
||||
@@ -74,17 +177,11 @@ class SubscriptionPieChartCard extends StatelessWidget {
|
||||
Shadow(color: Colors.black26, blurRadius: 2, offset: Offset(0, 1))
|
||||
],
|
||||
),
|
||||
color: colors[index],
|
||||
color: section.color,
|
||||
radius: radius,
|
||||
titlePositionPercentageOffset: 0.6,
|
||||
badgeWidget: isTouched
|
||||
? AnalysisBadge(
|
||||
size: 40,
|
||||
borderColor: colors[index],
|
||||
subscription: subscription,
|
||||
)
|
||||
: null,
|
||||
badgePositionPercentageOffset: .98,
|
||||
titlePositionPercentageOffset: section.titlePositionPercentageOffset,
|
||||
badgeWidget: isTouched ? _createBadgeWidget(i) : null,
|
||||
badgePositionPercentageOffset: section.badgePositionPercentageOffset,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -96,7 +193,7 @@ class SubscriptionPieChartCard extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: FadeTransition(
|
||||
opacity: CurvedAnimation(
|
||||
parent: animationController,
|
||||
parent: widget.animationController,
|
||||
curve: const Interval(0.0, 0.7, curve: Curves.easeOut),
|
||||
),
|
||||
child: SlideTransition(
|
||||
@@ -104,7 +201,7 @@ class SubscriptionPieChartCard extends StatelessWidget {
|
||||
begin: const Offset(0, 0.2),
|
||||
end: Offset.zero,
|
||||
).animate(CurvedAnimation(
|
||||
parent: animationController,
|
||||
parent: widget.animationController,
|
||||
curve: const Interval(0.0, 0.7, curve: Curves.easeOut),
|
||||
)),
|
||||
child: GlassmorphismCard(
|
||||
@@ -120,13 +217,15 @@ class SubscriptionPieChartCard extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ThemedText.headline(
|
||||
text: '구독 서비스 비율',
|
||||
text: AppLocalizations.of(context).subscriptionServiceRatio,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
FutureBuilder<String>(
|
||||
future: CurrencyUtil.getExchangeRateInfo(),
|
||||
future: CurrencyUtil.getExchangeRateInfoForLocale(
|
||||
context.watch<LocaleProvider>().locale.languageCode
|
||||
),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData &&
|
||||
snapshot.data!.isNotEmpty) {
|
||||
@@ -145,7 +244,7 @@ class SubscriptionPieChartCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
snapshot.data!,
|
||||
AppLocalizations.of(context).exchangeRateFormat(snapshot.data!),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
@@ -161,20 +260,20 @@ class SubscriptionPieChartCard extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ThemedText.subtitle(
|
||||
text: '월 지출 기준',
|
||||
text: AppLocalizations.of(context).monthlyExpenseBasis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Center(
|
||||
child: subscriptions.isEmpty
|
||||
? const SizedBox(
|
||||
child: widget.subscriptions.isEmpty
|
||||
? SizedBox(
|
||||
height: 250,
|
||||
child: Center(
|
||||
child: ThemedText(
|
||||
'구독중인 서비스가 없습니다',
|
||||
style: TextStyle(
|
||||
AppLocalizations.of(context).noSubscriptionServices,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
@@ -182,52 +281,90 @@ class SubscriptionPieChartCard extends StatelessWidget {
|
||||
)
|
||||
: SizedBox(
|
||||
height: 250,
|
||||
child: PieChart(
|
||||
PieChartData(
|
||||
borderData: FlBorderData(show: false),
|
||||
sectionsSpace: 2,
|
||||
centerSpaceRadius: 60,
|
||||
sections: _getPieSections(),
|
||||
pieTouchData: PieTouchData(
|
||||
touchCallback: (FlTouchEvent event,
|
||||
pieTouchResponse) {
|
||||
if (!event
|
||||
.isInterestedForInteractions ||
|
||||
pieTouchResponse == null ||
|
||||
pieTouchResponse
|
||||
.touchedSection ==
|
||||
null) {
|
||||
onPieTouch(-1);
|
||||
return;
|
||||
}
|
||||
onPieTouch(pieTouchResponse
|
||||
.touchedSection!
|
||||
.touchedSectionIndex);
|
||||
},
|
||||
),
|
||||
),
|
||||
child: FutureBuilder<List<PieChartSectionData>>(
|
||||
future: _pieSectionsFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
|
||||
if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
||||
return Center(
|
||||
child: ThemedText(
|
||||
AppLocalizations.of(context).noSubscriptionServices,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return PieChart(
|
||||
PieChartData(
|
||||
borderData: FlBorderData(show: false),
|
||||
sectionsSpace: 2,
|
||||
centerSpaceRadius: 60,
|
||||
sections: _applyTouchedState(snapshot.data!),
|
||||
pieTouchData: PieTouchData(
|
||||
enabled: true,
|
||||
touchCallback: (FlTouchEvent event,
|
||||
pieTouchResponse) {
|
||||
// 터치 응답이 없거나 섹션이 없는 경우
|
||||
if (pieTouchResponse == null ||
|
||||
pieTouchResponse.touchedSection == null) {
|
||||
// 차트 밖으로 나갔을 때만 리셋
|
||||
if (_touchedIndex != -1) {
|
||||
setState(() {
|
||||
_touchedIndex = -1;
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final touchedIndex = pieTouchResponse
|
||||
.touchedSection!
|
||||
.touchedSectionIndex;
|
||||
|
||||
// 탭 이벤트 처리 (토글)
|
||||
if (event is FlTapUpEvent) {
|
||||
setState(() {
|
||||
// 동일 섹션 탭하면 선택 해제, 아니면 선택
|
||||
_touchedIndex = (_touchedIndex == touchedIndex) ? -1 : touchedIndex;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// hover 이벤트 처리 (단순 표시)
|
||||
if (event is FlPointerHoverEvent ||
|
||||
event is FlPointerEnterEvent) {
|
||||
// 현재 인덱스와 다른 경우만 업데이트
|
||||
if (_touchedIndex != touchedIndex) {
|
||||
setState(() {
|
||||
_touchedIndex = touchedIndex;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// 서비스 목록
|
||||
Column(
|
||||
children: subscriptions.isEmpty
|
||||
children: widget.subscriptions.isEmpty
|
||||
? []
|
||||
: List.generate(
|
||||
subscriptions.length,
|
||||
widget.subscriptions.length,
|
||||
(index) {
|
||||
final subscription =
|
||||
subscriptions[index];
|
||||
final color = [
|
||||
const Color(0xFF3B82F6),
|
||||
const Color(0xFF10B981),
|
||||
const Color(0xFFF59E0B),
|
||||
const Color(0xFFEF4444),
|
||||
const Color(0xFF8B5CF6),
|
||||
const Color(0xFF0EA5E9),
|
||||
const Color(0xFFEC4899),
|
||||
][index % 7];
|
||||
widget.subscriptions[index];
|
||||
final color = _chartColors[index % _chartColors.length];
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
bottom: 4.0),
|
||||
@@ -254,8 +391,9 @@ class SubscriptionPieChartCard extends StatelessWidget {
|
||||
),
|
||||
FutureBuilder<String>(
|
||||
future: CurrencyUtil
|
||||
.formatSubscriptionAmount(
|
||||
subscription),
|
||||
.formatSubscriptionAmountWithLocale(
|
||||
subscription,
|
||||
context.read<LocaleProvider>().locale.languageCode),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return ThemedText(
|
||||
|
||||
Reference in New Issue
Block a user