fix(trading): 卖出金额超过可用积分股时提示并禁用确认按钮

- 新增 _getSellValidationError 校验方法
- 输入金额反算的积分股数量 > 可用余额时显示红色提示
- 校验失败时禁用"确认交易"按钮(灰色)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-31 22:29:33 -08:00
parent b8f8831516
commit 64d998c7b3
1 changed files with 30 additions and 6 deletions

View File

@ -645,10 +645,19 @@ class _TradingPageState extends ConsumerState<TradingPage> {
_selectedTab == 0 ? availableCash : null,
currentPrice,
),
//
// +
if (_selectedTab == 1) ...[
const SizedBox(height: 16),
_buildAmountInput(tradingShareBalance, currentPrice),
//
if (_getSellValidationError(tradingShareBalance) != null)
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
_getSellValidationError(tradingShareBalance)!,
style: const TextStyle(fontSize: 12, color: _red),
),
),
],
const SizedBox(height: 16),
//
@ -701,14 +710,17 @@ class _TradingPageState extends ConsumerState<TradingPage> {
),
),
const SizedBox(height: 24),
//
SizedBox(
//
Builder(builder: (context) {
final sellError = _selectedTab == 1 ? _getSellValidationError(tradingShareBalance) : null;
final isDisabled = sellError != null;
return SizedBox(
width: double.infinity,
height: 48,
child: ElevatedButton(
onPressed: _handleTrade,
onPressed: isDisabled ? null : _handleTrade,
style: ElevatedButton.styleFrom(
backgroundColor: _orange,
backgroundColor: isDisabled ? Colors.grey : _orange,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
@ -722,7 +734,8 @@ class _TradingPageState extends ConsumerState<TradingPage> {
),
),
),
),
);
}),
],
],
),
@ -957,6 +970,17 @@ class _TradingPageState extends ConsumerState<TradingPage> {
);
}
/// null
String? _getSellValidationError(String tradingShareBalance) {
final quantity = double.tryParse(_quantityController.text) ?? 0;
final available = double.tryParse(tradingShareBalance) ?? 0;
if (quantity <= 0) return null; //
if (quantity > available) {
return '交易账户积分股不足,需要 ${quantity.toStringAsFixed(4)},可用 ${formatAmount(tradingShareBalance)}';
}
return null;
}
/// (1 + burnMultiplier) × price × 0.9
double _getSellFactor() {
final price = double.tryParse(_priceController.text) ?? 0;