101 lines
3.3 KiB
Dart
101 lines
3.3 KiB
Dart
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 '../../providers/locale_provider.dart';
|
|
import '../../theme/app_colors.dart';
|
|
import '../../l10n/app_localizations.dart';
|
|
|
|
/// 파이 차트에서 선택된 섹션에 표시되는 배지 위젯
|
|
class AnalysisBadge extends StatelessWidget {
|
|
final double size;
|
|
final Color borderColor;
|
|
final SubscriptionModel subscription;
|
|
|
|
const AnalysisBadge({
|
|
super.key,
|
|
required this.size,
|
|
required this.borderColor,
|
|
required this.subscription,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AnimatedContainer(
|
|
duration: PieChart.defaultDuration,
|
|
width: size,
|
|
height: size,
|
|
decoration: BoxDecoration(
|
|
color: AppColors.pureWhite,
|
|
shape: BoxShape.circle,
|
|
border: Border.all(
|
|
color: borderColor,
|
|
width: 2,
|
|
),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: AppColors.shadowBlack,
|
|
blurRadius: 10,
|
|
spreadRadius: 2,
|
|
),
|
|
],
|
|
),
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
subscription.serviceName.length > 5
|
|
? '${subscription.serviceName.substring(0, 5)}...'
|
|
: subscription.serviceName,
|
|
style: const TextStyle(
|
|
fontSize: 8,
|
|
fontWeight: FontWeight.bold,
|
|
color: AppColors.darkNavy,
|
|
),
|
|
),
|
|
const SizedBox(height: 0),
|
|
FutureBuilder<String>(
|
|
future: CurrencyUtil.formatAmountWithLocale(
|
|
subscription.monthlyCost,
|
|
subscription.currency,
|
|
context.read<LocaleProvider>().locale.languageCode,
|
|
),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasData) {
|
|
final amountText = snapshot.data!;
|
|
// 금액이 너무 길면 축약 (괄호 제거)
|
|
String displayText = amountText;
|
|
if (amountText.length > 12) {
|
|
// 괄호 안의 내용 제거
|
|
displayText =
|
|
amountText.replaceAll(RegExp(r'\([^)]*\)'), '').trim();
|
|
}
|
|
if (displayText.length > 10) {
|
|
// 통화 기호만 남기고 숫자만 표시
|
|
final currencySymbol =
|
|
CurrencyUtil.getCurrencySymbol(subscription.currency);
|
|
displayText =
|
|
displayText.replaceAll(currencySymbol, '').trim();
|
|
displayText =
|
|
'$currencySymbol${displayText.substring(0, 6)}...';
|
|
}
|
|
return Text(
|
|
displayText,
|
|
style: const TextStyle(
|
|
fontSize: 7,
|
|
color: AppColors.navyGray,
|
|
),
|
|
);
|
|
}
|
|
return const SizedBox();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|