67 lines
2.1 KiB
Dart
67 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
||
import '../../../../core/theme/app_color_scheme.dart';
|
||
import '../../../../core/theme/app_spacing.dart';
|
||
import '../../../../core/theme/app_theme.dart';
|
||
|
||
/// 交易按鈕組件
|
||
///
|
||
/// CTA 買入/賣出按鈕。profit-green底 / sell-red底,圓角lg,高48,買入白字/賣出紅字16px bold。
|
||
class TradeButton extends StatelessWidget {
|
||
final bool isBuy;
|
||
final String? coinCode;
|
||
final bool enabled;
|
||
final bool isLoading;
|
||
final VoidCallback onPressed;
|
||
|
||
const TradeButton({
|
||
super.key,
|
||
required this.isBuy,
|
||
required this.coinCode,
|
||
required this.enabled,
|
||
required this.isLoading,
|
||
required this.onPressed,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final colorScheme = Theme.of(context).colorScheme;
|
||
final fillColor =
|
||
isBuy ? AppColorScheme.buyButtonFill : AppColorScheme.sellButtonFill;
|
||
// 買入按鈕文字為白色,賣出按鈕文字為紅色
|
||
final textColor = isBuy
|
||
? Colors.white
|
||
: (enabled ? AppColorScheme.sellButtonFill : colorScheme.onSurface.withOpacity(0.3));
|
||
|
||
return GestureDetector(
|
||
onTap: enabled ? onPressed : null,
|
||
child: AnimatedContainer(
|
||
duration: const Duration(milliseconds: 200),
|
||
height: 48,
|
||
decoration: BoxDecoration(
|
||
color: enabled ? fillColor : colorScheme.onSurface.withOpacity(0.08),
|
||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||
),
|
||
child: Center(
|
||
child: isLoading
|
||
? SizedBox(
|
||
width: 20,
|
||
height: 20,
|
||
child: CircularProgressIndicator(
|
||
strokeWidth: 2,
|
||
color: isBuy ? Colors.white : AppColorScheme.sellButtonFill,
|
||
),
|
||
)
|
||
: Text(
|
||
'${isBuy ? '買入' : '賣出'} ${coinCode ?? ""}',
|
||
style: AppTextStyles.headlineLarge(context).copyWith(
|
||
color: enabled
|
||
? textColor
|
||
: colorScheme.onSurface.withOpacity(0.3),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|