From 33233901a9462cb47125b3c2a8d16b443303b223 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 17 Jan 2026 22:49:46 -0800 Subject: [PATCH] =?UTF-8?q?debug(frontend):=20=E6=B7=BB=E5=8A=A0=E8=B5=84?= =?UTF-8?q?=E4=BA=A7=E9=A1=B5=E9=9D=A2=E5=AE=9A=E6=97=B6=E5=99=A8=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 debugPrint 日志帮助定位1秒刷新不生效的问题 Co-Authored-By: Claude Opus 4.5 --- .../presentation/pages/asset/asset_page.dart | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/frontend/mining-app/lib/presentation/pages/asset/asset_page.dart b/frontend/mining-app/lib/presentation/pages/asset/asset_page.dart index 9a5ce4ce..6e865a5b 100644 --- a/frontend/mining-app/lib/presentation/pages/asset/asset_page.dart +++ b/frontend/mining-app/lib/presentation/pages/asset/asset_page.dart @@ -48,7 +48,10 @@ class _AssetPageState extends ConsumerState { /// 启动定时器(使用外部传入的每秒增长值) void _startTimerWithGrowth(AssetDisplay asset, String perSecondEarning) { // 防止重复启动 - if (_timerStarted && _refreshTimer != null) return; + if (_timerStarted && _refreshTimer != null) { + debugPrint('[AssetPage] Timer already started, skipping'); + return; + } _refreshTimer?.cancel(); _elapsedSeconds = 0; @@ -58,11 +61,14 @@ class _AssetPageState extends ConsumerState { _growthPerSecond = double.tryParse(perSecondEarning) ?? 0; _timerStarted = true; + debugPrint('[AssetPage] Starting timer: perSecondEarning=$perSecondEarning, growthPerSecond=$_growthPerSecond, initialDisplayValue=$_initialDisplayValue'); + _refreshTimer = Timer.periodic(const Duration(seconds: 1), (timer) { if (mounted) { setState(() { _elapsedSeconds++; }); + debugPrint('[AssetPage] Timer tick: $_elapsedSeconds, currentDisplayValue=$_currentDisplayValue'); } }); } @@ -105,10 +111,15 @@ class _AssetPageState extends ConsumerState { final perSecondEarning = shareAccount?.perSecondEarning ?? '0'; final hasValidGrowth = (double.tryParse(perSecondEarning) ?? 0) > 0; + // 调试日志 + debugPrint('[AssetPage] build: accountSequence=$accountSequence, asset=${asset != null}, shareAccount=${shareAccount != null}'); + debugPrint('[AssetPage] build: perSecondEarning=$perSecondEarning, hasValidGrowth=$hasValidGrowth, _timerStarted=$_timerStarted, _lastAccountSequence=$_lastAccountSequence'); + // 当数据加载完成时启动定时器 if (asset != null && hasValidGrowth) { // 账户切换或首次加载时重置并启动定时器 if (_lastAccountSequence != accountSequence) { + debugPrint('[AssetPage] Account changed or first load, resetting timer'); _lastAccountSequence = accountSequence; _lastAsset = asset; _resetTimer(); @@ -117,6 +128,7 @@ class _AssetPageState extends ConsumerState { }); } else if (!_timerStarted) { // 定时器未启动时启动(例如页面刚进入) + debugPrint('[AssetPage] Timer not started, starting now'); _lastAsset = asset; WidgetsBinding.instance.addPostFrameCallback((_) { if (mounted) _startTimerWithGrowth(asset, perSecondEarning); @@ -125,7 +137,10 @@ class _AssetPageState extends ConsumerState { _lastAsset = asset; } } else if (asset != null) { + debugPrint('[AssetPage] Asset loaded but no valid growth: perSecondEarning=$perSecondEarning'); _lastAsset = asset; + } else { + debugPrint('[AssetPage] Asset is null, waiting for data'); } return Scaffold(