From 78d6b82305d815e920061b8a28ecb7d25c552c80 Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Mon, 21 Sep 2026 14:09:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=91=E5=AF=BC=E7=AC=AC=202=20?= =?UTF-8?q?=E6=AD=A5=E8=87=AA=E5=8A=A8=E8=BD=AE=E8=AF=A2=E2=80=94=E2=80=94?= =?UTF-8?q?=E6=89=8B=E5=8A=A8=E8=A3=85=E9=A9=B1=E5=8A=A8/=E6=8F=92?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=9C=BA=E5=90=8E=E9=A1=B5=E9=9D=A2=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户实测反馈:手动安装驱动输密码后向导页面无变化。排查确认驱动实际已装上 (/Library/Printers/HiTi 存在),问题是向导只在按钮事件时刷新——用户在 App 外装完驱动没有任何事件触发重建,页面停在"尚未安装"旧文案。 修复:向导停留在第 2 步期间每 3 秒静默轮询(驱动目录判断 + 打印机状态), 装完驱动/插上打印机/系统识别出队列后页面自动切换分支;驱动未装分支同时 补"重新检测"按钮;一键安装执行中暂停轮询避免打断。 --- lib/ui/setup_wizard.dart | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/ui/setup_wizard.dart b/lib/ui/setup_wizard.dart index b2cac5b..42f19e2 100644 --- a/lib/ui/setup_wizard.dart +++ b/lib/ui/setup_wizard.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:io'; import 'package:flutter/material.dart'; @@ -53,17 +54,32 @@ class _SetupWizardState extends State { void initState() { super.initState(); _checkPrinter(); + // 第 2 步期间自动轮询:用户手动装驱动 / 插上打印机后页面自动刷新 + // (驱动目录判断零成本;getStatus 走 lpoptions,3s 一次可接受) + _pollTimer = Timer.periodic(const Duration(seconds: 3), (_) { + if (_step == 1 && mounted && !_driverInstalling) { + _checkPrinter(silent: true); + } + }); } - Future _checkPrinter() async { - setState(() => _printerChecking = true); + Timer? _pollTimer; + + @override + void dispose() { + _pollTimer?.cancel(); + super.dispose(); + } + + Future _checkPrinter({bool silent = false}) async { + if (!silent) setState(() => _printerChecking = true); try { final status = await _agent.backend.getStatus(); if (mounted) setState(() => _printerStatus = status); } catch (_) { if (mounted) setState(() => _printerStatus = null); } finally { - if (mounted) setState(() => _printerChecking = false); + if (mounted && !silent) setState(() => _printerChecking = false); } } @@ -262,9 +278,15 @@ class _SetupWizardState extends State { ), const SizedBox(height: 8), Text( - '安装完成后:USB 连接打印机并开机,系统识别出现打印队列即完成。', + '安装完成后页面会自动刷新(也可手动重新检测);随后 USB 连接打印机并开机,系统识别出现打印队列即完成。', style: Theme.of(context).textTheme.bodySmall, ), + const SizedBox(height: 4), + TextButton.icon( + onPressed: _printerChecking ? null : () => _checkPrinter(), + icon: const Icon(Icons.refresh, size: 16), + label: const Text('重新检测'), + ), ] // 驱动已装但打印机未就绪 → 引导连接/添加队列