2026-04-05 22:38:56 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
import '../../../../core/theme/app_color_scheme.dart';
|
|
|
|
|
|
import '../../../../core/theme/app_spacing.dart';
|
2026-04-05 23:37:27 +08:00
|
|
|
|
import '../../../../core/theme/app_theme.dart';
|
2026-04-05 22:38:56 +08:00
|
|
|
|
|
2026-04-07 01:05:05 +08:00
|
|
|
|
/// 金額輸入框組件(含超額提示)
|
2026-04-05 22:38:56 +08:00
|
|
|
|
///
|
2026-04-07 01:05:05 +08:00
|
|
|
|
/// 設計稿:bg-tertiary,圓角md,高48。
|
|
|
|
|
|
/// 輸入金額超過可用 USDT 餘額時顯示警告提示。
|
2026-04-05 22:38:56 +08:00
|
|
|
|
class AmountInput extends StatefulWidget {
|
|
|
|
|
|
final TextEditingController amountController;
|
|
|
|
|
|
final String maxAmount;
|
|
|
|
|
|
final bool isBuy;
|
|
|
|
|
|
final Color actionColor;
|
|
|
|
|
|
final VoidCallback onChanged;
|
|
|
|
|
|
|
|
|
|
|
|
const AmountInput({
|
|
|
|
|
|
super.key,
|
|
|
|
|
|
required this.amountController,
|
|
|
|
|
|
required this.maxAmount,
|
|
|
|
|
|
required this.isBuy,
|
|
|
|
|
|
required this.actionColor,
|
|
|
|
|
|
required this.onChanged,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
State<AmountInput> createState() => _AmountInputState();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _AmountInputState extends State<AmountInput> {
|
|
|
|
|
|
bool _isExceeded = false;
|
|
|
|
|
|
|
|
|
|
|
|
void _checkLimit() {
|
|
|
|
|
|
final input = double.tryParse(widget.amountController.text) ?? 0;
|
|
|
|
|
|
final max = double.tryParse(widget.maxAmount) ?? 0;
|
|
|
|
|
|
final exceeded = widget.isBuy && input > max && max > 0 && input > 0;
|
|
|
|
|
|
if (exceeded != _isExceeded) {
|
|
|
|
|
|
setState(() => _isExceeded = exceeded);
|
|
|
|
|
|
}
|
|
|
|
|
|
widget.onChanged();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void initState() {
|
|
|
|
|
|
super.initState();
|
|
|
|
|
|
widget.amountController.addListener(_checkLimit);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void dispose() {
|
|
|
|
|
|
widget.amountController.removeListener(_checkLimit);
|
|
|
|
|
|
super.dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
|
|
final warningColor = AppColorScheme.warning;
|
|
|
|
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Container(
|
|
|
|
|
|
height: 48,
|
|
|
|
|
|
decoration: BoxDecoration(
|
2026-04-07 01:05:05 +08:00
|
|
|
|
color: colorScheme.surfaceContainerHighest.withOpacity(0.5), // 調整透明度
|
2026-04-05 22:38:56 +08:00
|
|
|
|
borderRadius: BorderRadius.circular(AppRadius.md),
|
|
|
|
|
|
),
|
|
|
|
|
|
child: TextField(
|
|
|
|
|
|
controller: widget.amountController,
|
|
|
|
|
|
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
|
|
|
|
|
onChanged: (_) => _checkLimit(),
|
2026-04-05 23:37:27 +08:00
|
|
|
|
style: AppTextStyles.numberMedium(context).copyWith(
|
|
|
|
|
|
fontWeight: FontWeight.w400,
|
2026-04-05 22:38:56 +08:00
|
|
|
|
),
|
|
|
|
|
|
decoration: InputDecoration(
|
2026-04-07 01:05:05 +08:00
|
|
|
|
hintText: '請輸入金額',
|
2026-04-05 23:37:27 +08:00
|
|
|
|
hintStyle: AppTextStyles.numberMedium(context).copyWith(
|
|
|
|
|
|
fontWeight: FontWeight.w400,
|
2026-04-05 22:38:56 +08:00
|
|
|
|
color: colorScheme.onSurfaceVariant.withOpacity(0.5),
|
|
|
|
|
|
),
|
|
|
|
|
|
border: InputBorder.none,
|
|
|
|
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
|
|
|
|
horizontal: AppSpacing.md,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
if (_isExceeded)
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
padding: EdgeInsets.only(top: AppSpacing.xs),
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
children: [
|
|
|
|
|
|
Icon(Icons.error_outline, size: 13, color: warningColor),
|
2026-04-05 23:37:27 +08:00
|
|
|
|
SizedBox(width: AppSpacing.xs),
|
2026-04-05 22:38:56 +08:00
|
|
|
|
Text(
|
2026-04-07 01:05:05 +08:00
|
|
|
|
'超出可用USDT餘額',
|
2026-04-05 23:37:27 +08:00
|
|
|
|
style: AppTextStyles.bodySmall(context).copyWith(
|
2026-04-05 22:38:56 +08:00
|
|
|
|
color: warningColor,
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|