Files
submanager/lib/widgets/detail/detail_event_section.dart
JiWoong Sul 83c5e3d64e Refactor screens to MVC architecture with modular widgets
- Extract business logic from screens into dedicated controllers
- Split large screen files into smaller, reusable widget components
- Add controllers for AddSubscriptionScreen and DetailScreen
- Create modular widgets for subscription and detail features
- Improve code organization and maintainability
- Remove duplicated code and improve reusability

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-11 00:21:18 +09:00

221 lines
7.7 KiB
Dart

import 'package:flutter/material.dart';
import '../../controllers/detail_screen_controller.dart';
import '../common/form_fields/currency_input_field.dart';
import '../common/form_fields/date_picker_field.dart';
/// 이벤트 가격 섹션
/// 할인 이벤트 정보를 관리하는 섹션입니다.
class DetailEventSection extends StatelessWidget {
final DetailScreenController controller;
final Animation<double> fadeAnimation;
final Animation<Offset> slideAnimation;
const DetailEventSection({
super.key,
required this.controller,
required this.fadeAnimation,
required this.slideAnimation,
});
@override
Widget build(BuildContext context) {
final baseColor = controller.getCardColor();
return FadeTransition(
opacity: fadeAnimation,
child: SlideTransition(
position: Tween<Offset>(
begin: const Offset(0.0, 0.8),
end: Offset.zero,
).animate(CurvedAnimation(
parent: controller.animationController!,
curve: const Interval(0.4, 1.0, curve: Curves.easeOutCubic),
)),
child: Card(
elevation: 1,
shadowColor: Colors.black12,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 헤더
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: baseColor.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
),
child: Icon(
Icons.local_offer_rounded,
color: baseColor,
size: 24,
),
),
const SizedBox(width: 12),
const Text(
'이벤트 가격',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w700,
),
),
],
),
// 이벤트 활성화 스위치
Switch.adaptive(
value: controller.isEventActive,
onChanged: (value) {
controller.isEventActive = value;
if (!value) {
// 이벤트 비활성화시 관련 정보 초기화
controller.eventStartDate = null;
controller.eventEndDate = null;
controller.eventPriceController.clear();
}
},
activeColor: baseColor,
),
],
),
// 이벤트 활성화시 표시될 필드들
if (controller.isEventActive) ...[
const SizedBox(height: 20),
// 이벤트 설명
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.blue.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Icon(
Icons.info_outline_rounded,
color: Colors.blue[700],
size: 20,
),
const SizedBox(width: 8),
Expanded(
child: Text(
'할인 또는 프로모션 가격을 설정하세요',
style: TextStyle(
fontSize: 14,
color: Colors.blue[700],
),
),
),
],
),
),
const SizedBox(height: 20),
// 이벤트 기간
DateRangePickerField(
startDate: controller.eventStartDate,
endDate: controller.eventEndDate,
onStartDateSelected: (date) {
controller.eventStartDate = date;
},
onEndDateSelected: (date) {
controller.eventEndDate = date;
},
startLabel: '시작일',
endLabel: '종료일',
primaryColor: baseColor,
),
const SizedBox(height: 20),
// 이벤트 가격
CurrencyInputField(
controller: controller.eventPriceController,
currency: controller.currency,
label: '이벤트 가격',
hintText: '할인된 가격을 입력하세요',
),
const SizedBox(height: 16),
// 할인율 표시
if (controller.eventPriceController.text.isNotEmpty)
_DiscountBadge(
originalPrice: controller.subscription.monthlyCost,
eventPrice: double.tryParse(
controller.eventPriceController.text.replaceAll(',', '')
) ?? 0,
currency: controller.currency,
),
],
],
),
),
),
),
);
}
}
/// 할인율 배지
class _DiscountBadge extends StatelessWidget {
final double originalPrice;
final double eventPrice;
final String currency;
const _DiscountBadge({
required this.originalPrice,
required this.eventPrice,
required this.currency,
});
@override
Widget build(BuildContext context) {
if (eventPrice >= originalPrice || eventPrice <= 0) {
return const SizedBox.shrink();
}
final discountPercentage = ((originalPrice - eventPrice) / originalPrice * 100).round();
final discountAmount = originalPrice - eventPrice;
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.green.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(8),
),
child: Text(
'$discountPercentage% 할인',
style: const TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
),
const SizedBox(width: 12),
Text(
currency == 'KRW'
? '${discountAmount.toInt().toString()}원 절약'
: '\$${discountAmount.toStringAsFixed(2)} 절약',
style: TextStyle(
color: Colors.green[700],
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
],
),
);
}
}