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:
hailin 2026-02-04 21:14:16 -08:00
parent b639b5d499
commit abb0da36a9
2 changed files with 36 additions and 9 deletions

View File

@ -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]);
});
// 060
_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(

View File

@ -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());