Files
submanager/lib/widgets/common/form_fields/currency_selector.dart
2025-09-07 19:33:11 +09:00

158 lines
4.1 KiB
Dart

import 'package:flutter/material.dart';
import '../../../theme/app_colors.dart';
/// 통화 선택 위젯
/// KRW(원화), USD(달러), JPY(엔화), CNY(위안화) 중 선택할 수 있습니다.
class CurrencySelector extends StatelessWidget {
final String currency;
final ValueChanged<String> onChanged;
final bool isGlassmorphism;
const CurrencySelector({
super.key,
required this.currency,
required this.onChanged,
this.isGlassmorphism = false,
});
@override
Widget build(BuildContext context) {
return Column(
children: [
Row(
children: [
_CurrencyOption(
label: '',
value: 'KRW',
isSelected: currency == 'KRW',
onTap: () => onChanged('KRW'),
isGlassmorphism: isGlassmorphism,
),
const SizedBox(width: 8),
_CurrencyOption(
label: '\$',
value: 'USD',
isSelected: currency == 'USD',
onTap: () => onChanged('USD'),
isGlassmorphism: isGlassmorphism,
),
],
),
const SizedBox(height: 8),
Row(
children: [
_CurrencyOption(
label: '¥',
value: 'JPY',
subtitle: 'JPY',
isSelected: currency == 'JPY',
onTap: () => onChanged('JPY'),
isGlassmorphism: isGlassmorphism,
),
const SizedBox(width: 8),
_CurrencyOption(
label: '¥',
value: 'CNY',
subtitle: 'CNY',
isSelected: currency == 'CNY',
onTap: () => onChanged('CNY'),
isGlassmorphism: isGlassmorphism,
),
],
),
],
);
}
}
/// 통화 옵션 버튼
class _CurrencyOption extends StatelessWidget {
final String label;
final String value;
final String? subtitle;
final bool isSelected;
final VoidCallback onTap;
final bool isGlassmorphism;
const _CurrencyOption({
required this.label,
required this.value,
this.subtitle,
required this.isSelected,
required this.onTap,
required this.isGlassmorphism,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Expanded(
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 12),
decoration: BoxDecoration(
color: _getBackgroundColor(theme),
borderRadius: BorderRadius.circular(12),
border: _getBorder(),
),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
label,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: _getTextColor(),
),
),
if (subtitle != null) ...[
const SizedBox(height: 2),
Text(
subtitle!,
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w500,
color: _getTextColor().withValues(alpha: 0.8),
),
),
],
],
),
),
),
),
);
}
Color _getBackgroundColor(ThemeData theme) {
if (isSelected) {
return isGlassmorphism ? theme.primaryColor : const Color(0xFF3B82F6);
}
return isGlassmorphism
? AppColors.surfaceColorAlt
: Colors.grey.withValues(alpha: 0.1);
}
Border? _getBorder() {
if (isSelected || !isGlassmorphism) {
return null;
}
return Border.all(
color: AppColors.borderColor,
width: 1.5,
);
}
Color _getTextColor() {
if (isSelected) {
return Colors.white;
}
return isGlassmorphism ? AppColors.navyGray : Colors.grey[600]!;
}
}