feat: adopt material 3 theme and billing adjustments

This commit is contained in:
JiWoong Sul
2025-09-16 14:30:14 +09:00
parent a01d9092ba
commit 44850a53cc
85 changed files with 2957 additions and 2776 deletions

View File

@@ -5,10 +5,12 @@ import '../providers/category_provider.dart';
import '../providers/locale_provider.dart';
import '../services/subscription_url_matcher.dart';
import '../services/currency_util.dart';
import '../utils/billing_date_util.dart';
import 'website_icon.dart';
import 'app_navigator.dart';
import '../theme/app_colors.dart';
import 'glassmorphism_card.dart';
// import '../theme/app_colors.dart';
import '../theme/color_scheme_ext.dart';
// import 'glassmorphism_card.dart';
import '../l10n/app_localizations.dart';
class SubscriptionCard extends StatefulWidget {
@@ -30,6 +32,7 @@ class _SubscriptionCardState extends State<SubscriptionCard>
late AnimationController _hoverController;
bool _isHovering = false;
String? _displayName;
static const int _nearBillingThresholdDays = 3;
@override
void initState() {
@@ -107,6 +110,16 @@ class _SubscriptionCardState extends State<SubscriptionCard>
// 과거 날짜인 경우, 다음 결제일 계산
final billingCycle = widget.subscription.billingCycle;
final norm = BillingDateUtil.normalizeCycle(billingCycle);
// 분기/반기 구독 처리
if (norm == 'quarterly' || norm == 'half-yearly') {
final nextDate =
BillingDateUtil.ensureFutureDate(nextBillingDate, billingCycle);
final days = nextDate.difference(dateOnlyNow).inDays;
if (days == 0) return AppLocalizations.of(context).paymentDueToday;
return AppLocalizations.of(context).paymentDueInDays(days);
}
// 월간 구독인 경우
if (SubscriptionModel.normalizeBillingCycle(billingCycle) == 'monthly') {
@@ -211,26 +224,32 @@ class _SubscriptionCardState extends State<SubscriptionCard>
return AppLocalizations.of(context).paymentInfoNeeded;
}
// 결제일이 가까운지 확인 (7일 이내)
bool _isNearBilling() {
final text = _getNextBillingText();
if (text == AppLocalizations.of(context).paymentDueToday) return true;
int _daysUntilNextBilling() {
final now = DateTime.now();
final dateOnlyNow = DateTime(now.year, now.month, now.day);
final nbd = widget.subscription.nextBillingDate;
final dateOnlyBilling = DateTime(nbd.year, nbd.month, nbd.day);
final regex = RegExp(r'(\d+)');
final match = regex.firstMatch(text);
if (match != null) {
final days = int.parse(match.group(1) ?? '0');
return days <= 7;
if (dateOnlyBilling.isAfter(dateOnlyNow)) {
return dateOnlyBilling.difference(dateOnlyNow).inDays;
}
return false;
final next =
BillingDateUtil.ensureFutureDate(nbd, widget.subscription.billingCycle);
return next.difference(dateOnlyNow).inDays;
}
// 결제일이 가까운지 확인
bool _isNearBilling() {
final days = _daysUntilNextBilling();
return days <= _nearBillingThresholdDays;
}
// 카테고리별 그라데이션 색상 생성
List<Color> _getCategoryGradientColors(BuildContext context) {
try {
if (widget.subscription.categoryId == null) {
return AppColors.blueGradient;
return [Theme.of(context).colorScheme.primary];
}
final categoryProvider = context.watch<CategoryProvider>();
@@ -238,19 +257,16 @@ class _SubscriptionCardState extends State<SubscriptionCard>
categoryProvider.getCategoryById(widget.subscription.categoryId!);
if (category == null) {
return AppColors.blueGradient;
return [Theme.of(context).colorScheme.primary];
}
final categoryColor =
Color(int.parse(category.color.replaceAll('#', '0xFF')));
return [
categoryColor,
categoryColor.withValues(alpha: 0.8),
];
return [categoryColor];
} catch (e) {
// 색상 파싱 실패 시 기본 파란색 그라데이션 반환
return AppColors.blueGradient;
// 색상 파싱 실패 시 기본 primary 색 반환
return [Theme.of(context).colorScheme.primary];
}
}
@@ -296,328 +312,362 @@ class _SubscriptionCardState extends State<SubscriptionCard>
child: MouseRegion(
onEnter: (_) => _onHover(true),
onExit: (_) => _onHover(false),
child: AnimatedGlassmorphismCard(
padding: EdgeInsets.zero,
borderRadius: 16,
blur: _isHovering ? 15 : 10,
width: double.infinity, // 전체 너비를 차지하도록 설정
onTap: widget.onTap ??
() async {
// ignore: use_build_context_synchronously
await AppNavigator.toDetail(context, widget.subscription);
},
child: Column(
children: [
// 그라데이션 상단 바 효과
AnimatedContainer(
duration: const Duration(milliseconds: 200),
height: 4,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: widget.subscription.isCurrentlyInEvent
? [
const Color(0xFFFF6B6B),
const Color(0xFFFF8787),
]
: isNearBilling
? AppColors.amberGradient
: _getCategoryGradientColors(context),
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
child: Card(
elevation: _isHovering ? 2 : 1,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
side: BorderSide(
color:
Theme.of(context).colorScheme.outline.withValues(alpha: 0.4),
width: 1,
),
),
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: widget.onTap ??
() async {
// ignore: use_build_context_synchronously
await AppNavigator.toDetail(context, widget.subscription);
},
child: Column(
children: [
// 그라데이션 상단 바 효과
AnimatedContainer(
duration: const Duration(milliseconds: 200),
height: 4,
// 카테고리 우선: 상단 바는 항상 카테고리 색
color: _getCategoryGradientColors(context).first,
),
),
Padding(
padding: const EdgeInsets.all(16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 서비스 아이콘
WebsiteIcon(
key: ValueKey(
'subscription_icon_${widget.subscription.id}'),
url: widget.subscription.websiteUrl,
serviceName: widget.subscription.serviceName,
size: 48,
isHovered: _isHovering,
),
const SizedBox(width: 16),
Padding(
padding: const EdgeInsets.all(16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 서비스 아이콘
WebsiteIcon(
key: ValueKey(
'subscription_icon_${widget.subscription.id}'),
url: widget.subscription.websiteUrl,
serviceName: widget.subscription.serviceName,
size: 48,
isHovered: _isHovering,
),
const SizedBox(width: 16),
// 서비스 정보
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// 서비스명
Flexible(
child: Text(
_displayName ??
widget.subscription.serviceName,
style: const TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18,
color: AppColors
.darkNavy, // color.md 가이드: 메인 텍스트
// 서비스 정보
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// 서비스명
Flexible(
child: Text(
_displayName ??
widget.subscription.serviceName,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18,
color: Theme.of(context)
.colorScheme
.onSurface,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
// 배지들
Row(
mainAxisSize: MainAxisSize.min,
children: [
// 이벤트 배지
if (widget
.subscription.isCurrentlyInEvent) ...[
// 배지들
Row(
mainAxisSize: MainAxisSize.min,
children: [
// 이벤트 배지
if (widget
.subscription.isCurrentlyInEvent) ...[
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 3,
),
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.error,
borderRadius:
BorderRadius.circular(12),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.local_offer_rounded,
size: 11,
color: Theme.of(context)
.colorScheme
.onError,
),
const SizedBox(width: 3),
Text(
AppLocalizations.of(context)
.event,
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: Theme.of(context)
.colorScheme
.onError,
),
),
],
),
),
const SizedBox(width: 6),
],
// 결제 주기 배지
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 3,
),
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [
Color(0xFFFF6B6B),
Color(0xFFFF8787),
],
),
color: Theme.of(context)
.colorScheme
.surface,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: Theme.of(context)
.colorScheme
.outline
.withValues(alpha: 0.5),
width: 0.5,
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
child: Text(
AppLocalizations.of(context)
.getBillingCycleName(widget
.subscription.billingCycle),
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: Theme.of(context)
.colorScheme
.onSurfaceVariant,
),
),
),
],
),
],
),
const SizedBox(height: 6),
// 가격 정보
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// 가격 표시 (이벤트 가격 반영)
// 가격 표시 (언어별 통화)
FutureBuilder<String>(
future: _getFormattedPrice(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const SizedBox();
}
if (widget
.subscription.isCurrentlyInEvent &&
snapshot.data!.contains('|')) {
final prices = snapshot.data!.split('|');
return Row(
children: [
const Icon(
Icons.local_offer_rounded,
size: 11,
color: AppColors.pureWhite,
),
const SizedBox(width: 3),
Text(
AppLocalizations.of(context).event,
style: const TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: AppColors.pureWhite,
prices[0],
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Theme.of(context)
.colorScheme
.onSurfaceVariant,
decoration:
TextDecoration.lineThrough,
),
),
const SizedBox(width: 8),
Text(
prices[1],
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w700,
color: Theme.of(context)
.colorScheme
.error,
),
),
],
),
),
const SizedBox(width: 6),
],
// 결제 주기 배지
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 3,
),
decoration: BoxDecoration(
color: AppColors.surfaceColorAlt,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: AppColors.borderColor,
width: 0.5,
),
),
child: Text(
AppLocalizations.of(context)
.getBillingCycleName(
widget.subscription.billingCycle),
style: const TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: AppColors
.navyGray, // color.md 가이드: 서브 텍스트
),
),
),
],
),
],
),
const SizedBox(height: 6),
// 가격 정보
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// 가격 표시 (이벤트 가격 반영)
// 가격 표시 (언어별 통화)
FutureBuilder<String>(
future: _getFormattedPrice(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const SizedBox();
}
if (widget.subscription.isCurrentlyInEvent &&
snapshot.data!.contains('|')) {
final prices = snapshot.data!.split('|');
return Row(
children: [
Text(
prices[0],
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: AppColors.navyGray,
decoration:
TextDecoration.lineThrough,
),
);
} else {
return Text(
snapshot.data!,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w700,
color: widget.subscription
.isCurrentlyInEvent
? Theme.of(context)
.colorScheme
.error
: Theme.of(context)
.colorScheme
.primary,
),
const SizedBox(width: 8),
Text(
prices[1],
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w700,
color: Color(0xFFFF6B6B),
),
),
],
);
} else {
return Text(
snapshot.data!,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w700,
color: widget
.subscription.isCurrentlyInEvent
? const Color(0xFFFF6B6B)
: AppColors.primaryColor,
),
);
}
},
),
);
}
},
),
// 결제 예정일 정보
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 3,
),
decoration: BoxDecoration(
color: isNearBilling
? AppColors.warningColor
.withValues(alpha: 0.1)
: AppColors.successColor
.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
isNearBilling
? Icons.access_time_filled_rounded
: Icons.check_circle_rounded,
size: 12,
color: isNearBilling
? AppColors.warningColor
: AppColors.successColor,
),
const SizedBox(width: 4),
Text(
_getNextBillingText(),
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: isNearBilling
? AppColors.warningColor
: AppColors.successColor,
),
),
],
),
),
],
),
// 이벤트 절약액 표시
if (widget.subscription.isCurrentlyInEvent &&
widget.subscription.eventSavings > 0) ...[
const SizedBox(height: 4),
Row(
children: [
// 결제 예정일 정보
Container(
padding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 2,
horizontal: 8,
vertical: 3,
),
decoration: BoxDecoration(
color: const Color(0xFFFF6B6B)
color: (isNearBilling
? Theme.of(context)
.colorScheme
.warning
: Theme.of(context)
.colorScheme
.success)
.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.savings_rounded,
size: 14,
color: Color(0xFFFF6B6B),
Icon(
isNearBilling
? Icons.access_time_filled_rounded
: Icons.check_circle_rounded,
size: 12,
color: isNearBilling
? Theme.of(context)
.colorScheme
.warning
: Theme.of(context)
.colorScheme
.success,
),
const SizedBox(width: 4),
// 이벤트 절약액 표시 (언어별 통화)
FutureBuilder<String>(
future: CurrencyUtil
.formatEventSavingsWithLocale(
widget.subscription,
localeProvider.locale.languageCode,
Text(
_getNextBillingText(),
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: isNearBilling
? Theme.of(context)
.colorScheme
.warning
: Theme.of(context)
.colorScheme
.success,
),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const SizedBox();
}
return Text(
'${snapshot.data!} ${AppLocalizations.of(context).saving}',
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Color(0xFFFF6B6B),
),
);
},
),
],
),
),
const SizedBox(width: 8),
// 이벤트 종료일까지 남은 일수
if (widget.subscription.eventEndDate !=
null) ...[
Text(
AppLocalizations.of(context).daysRemaining(
widget.subscription.eventEndDate!
.difference(DateTime.now())
.inDays),
style: const TextStyle(
fontSize: 11,
color: AppColors
.navyGray, // color.md 가이드: 서브 텍스트
),
),
],
],
),
// 이벤트 절약액 표시
if (widget.subscription.isCurrentlyInEvent &&
widget.subscription.eventSavings > 0) ...[
const SizedBox(height: 4),
Row(
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 6,
vertical: 2,
),
decoration: BoxDecoration(
color: Theme.of(context)
.colorScheme
.error
.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.savings_rounded,
size: 14,
color: Theme.of(context)
.colorScheme
.error,
),
const SizedBox(width: 4),
// 이벤트 절약액 표시 (언어별 통화)
FutureBuilder<String>(
future: CurrencyUtil
.formatEventSavingsWithLocale(
widget.subscription,
localeProvider.locale.languageCode,
),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const SizedBox();
}
return Text(
'${snapshot.data!} ${AppLocalizations.of(context).saving}',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Theme.of(context)
.colorScheme
.error,
),
);
},
),
],
),
),
const SizedBox(width: 8),
// 이벤트 종료일까지 남은 일수
if (widget.subscription.eventEndDate !=
null) ...[
Text(
AppLocalizations.of(context)
.daysRemaining(widget
.subscription.eventEndDate!
.difference(DateTime.now())
.inDays),
style: TextStyle(
fontSize: 11,
color: Theme.of(context)
.colorScheme
.onSurfaceVariant,
),
),
],
],
),
],
],
],
),
),
),
],
],
),
),
),
],
],
),
),
),
),