feat(mining-app): 兑换页价格刷新改为60秒并显示倒计时
- 价格 Provider 刷新间隔从15秒改为60秒,与后端销毁调度器同步 (销毁每分钟执行一次,15秒内数据不会变化,避免无意义请求) - 兑换页"当前积分股价值"右侧新增倒计时显示(60s→1s) 让用户直观知道下次数据刷新时间 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
b639b5d499
commit
abb0da36a9
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
|
@ -41,12 +42,15 @@ class _TradingPageState extends ConsumerState<TradingPage> {
|
|||
bool _isEditingQuantity = false; // 正在编辑数量(防止循环更新)
|
||||
bool _isEditingAmount = false; // 正在编辑金额(防止循环更新)
|
||||
bool _isFullScreen = false; // K线图全屏状态
|
||||
int _countdown = 60; // 价格刷新倒计时(秒)
|
||||
Timer? _countdownTimer;
|
||||
|
||||
// K线周期选项:分钟级 → 小时级 → 日/周/月/年
|
||||
final List<String> _timeRanges = ['1分', '5分', '15分', '30分', '1时', '4时', '日', '周', '月', '年'];
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_countdownTimer?.cancel();
|
||||
_quantityController.dispose();
|
||||
_priceController.dispose();
|
||||
_amountInputController.dispose();
|
||||
|
|
@ -60,6 +64,16 @@ class _TradingPageState extends ConsumerState<TradingPage> {
|
|||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
ref.read(klinesNotifierProvider.notifier).loadKlines(_timeRanges[_selectedTimeRange]);
|
||||
});
|
||||
// 启动价格刷新倒计时(每秒递减,到0时重置为60)
|
||||
_countdownTimer = Timer.periodic(const Duration(seconds: 1), (_) {
|
||||
setState(() {
|
||||
if (_countdown <= 1) {
|
||||
_countdown = 60;
|
||||
} else {
|
||||
_countdown--;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -165,13 +179,26 @@ class _TradingPageState extends ConsumerState<TradingPage> {
|
|||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'当前积分股价值',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.textSecondaryOf(context),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
'当前积分股价值',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.textSecondaryOf(context),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
// 刷新倒计时
|
||||
Text(
|
||||
'${_countdown}s',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: AppColors.textSecondaryOf(context).withValues(alpha: 0.6),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
|
|
|
|||
|
|
@ -261,13 +261,13 @@ final klinesProvider = FutureProvider<List<Kline>>((ref) async {
|
|||
);
|
||||
});
|
||||
|
||||
// 当前价格 Provider (15秒缓存 - 交易页面需要快速更新)
|
||||
// 当前价格 Provider (60秒缓存 - 与销毁调度器同步,每分钟刷新一次)
|
||||
final currentPriceProvider = FutureProvider<PriceInfo?>((ref) async {
|
||||
final repository = ref.watch(tradingRepositoryProvider);
|
||||
final result = await repository.getCurrentPrice();
|
||||
|
||||
ref.keepAlive();
|
||||
final timer = Timer(const Duration(seconds: 15), () {
|
||||
final timer = Timer(const Duration(seconds: 60), () {
|
||||
ref.invalidateSelf();
|
||||
});
|
||||
ref.onDispose(() => timer.cancel());
|
||||
|
|
|
|||
Loading…
Reference in New Issue