fix(mining-app): 价格刷新倒计时与后端销毁调度器同步

- 倒计时不再从页面打开时任意起点开始
- 自动计算距下一个整分钟第3秒的剩余秒数作为初始值
  (销毁在每分钟第0秒执行,留3秒余量等数据库写完)
- 倒计时归零时通过 ref.invalidate 主动刷新价格数据
- 确保每次刷新都能拿到最新的销毁后价格

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-04 21:17:10 -08:00
parent abb0da36a9
commit ef5ac2bf94
1 changed files with 8 additions and 1 deletions

View File

@ -64,10 +64,17 @@ class _TradingPageState extends ConsumerState<TradingPage> {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
ref.read(klinesNotifierProvider.notifier).loadKlines(_timeRanges[_selectedTimeRange]); ref.read(klinesNotifierProvider.notifier).loadKlines(_timeRanges[_selectedTimeRange]);
}); });
// 060 // 03
// 3
final now = DateTime.now();
final secsIntoMinute = now.second;
// 3+3
_countdown = secsIntoMinute < 3 ? (3 - secsIntoMinute) : (63 - secsIntoMinute);
_countdownTimer = Timer.periodic(const Duration(seconds: 1), (_) { _countdownTimer = Timer.periodic(const Duration(seconds: 1), (_) {
setState(() { setState(() {
if (_countdown <= 1) { if (_countdown <= 1) {
//
ref.invalidate(currentPriceProvider);
_countdown = 60; _countdown = 60;
} else { } else {
_countdown--; _countdown--;