fix: auto repair bugs #53

This commit is contained in:
repair-agent 2026-02-28 14:57:20 +08:00
parent 3f7b38a59b
commit 3a89ad4b55
2 changed files with 20 additions and 4 deletions

View File

@ -25,6 +25,7 @@ class DeviceController extends _$DeviceController {
return result.fold( return result.fold(
(failure) => false, (failure) => false,
(bindingId) { (bindingId) {
if (!ref.mounted) return false;
ref.invalidateSelf(); ref.invalidateSelf();
return true; return true;
}, },
@ -38,6 +39,7 @@ class DeviceController extends _$DeviceController {
return result.fold( return result.fold(
(failure) => false, (failure) => false,
(_) { (_) {
if (!ref.mounted) return false;
final current = state.value ?? []; final current = state.value ?? [];
state = AsyncData( state = AsyncData(
current.where((d) => d.id != userDeviceId).toList(), current.where((d) => d.id != userDeviceId).toList(),
@ -54,6 +56,7 @@ class DeviceController extends _$DeviceController {
return result.fold( return result.fold(
(failure) => false, (failure) => false,
(updated) { (updated) {
if (!ref.mounted) return false;
ref.invalidateSelf(); ref.invalidateSelf();
return true; return true;
}, },
@ -61,6 +64,7 @@ class DeviceController extends _$DeviceController {
} }
void refresh() { void refresh() {
if (!ref.mounted) return;
ref.invalidateSelf(); ref.invalidateSelf();
} }
} }
@ -85,6 +89,7 @@ class DeviceDetailController extends _$DeviceDetailController {
return result.fold( return result.fold(
(failure) => false, (failure) => false,
(_) { (_) {
if (!ref.mounted) return false;
ref.invalidateSelf(); ref.invalidateSelf();
return true; return true;
}, },
@ -98,6 +103,7 @@ class DeviceDetailController extends _$DeviceDetailController {
return result.fold( return result.fold(
(failure) => false, (failure) => false,
(_) { (_) {
if (!ref.mounted) return false;
ref.invalidateSelf(); ref.invalidateSelf();
return true; return true;
}, },
@ -105,6 +111,7 @@ class DeviceDetailController extends _$DeviceDetailController {
} }
void refresh() { void refresh() {
if (!ref.mounted) return;
ref.invalidateSelf(); ref.invalidateSelf();
} }
} }

View File

@ -29,6 +29,7 @@ class _WifiConfigPageState extends ConsumerState<WifiConfigPage>
double _progress = 0.0; double _progress = 0.0;
String _progressText = '正在连接WiFi...'; String _progressText = '正在连接WiFi...';
bool _connectFailed = false; bool _connectFailed = false;
bool _isBinding = false;
// Device Info // Device Info
Map<String, dynamic> _deviceInfo = {}; Map<String, dynamic> _deviceInfo = {};
@ -128,12 +129,20 @@ class _WifiConfigPageState extends ConsumerState<WifiConfigPage>
if (_currentStep == 2 && _passwordController.text.isEmpty) return; if (_currentStep == 2 && _passwordController.text.isEmpty) return;
if (_currentStep == 4) { if (_currentStep == 4) {
if (_isBinding) return;
setState(() => _isBinding = true);
final sn = _deviceInfo['sn'] as String? ?? ''; final sn = _deviceInfo['sn'] as String? ?? '';
if (sn.isNotEmpty) { if (sn.isNotEmpty) {
debugPrint('[WiFi Config] Binding device sn=$sn'); try {
await ref.read(deviceControllerProvider.notifier).bindDevice(sn); debugPrint('[WiFi Config] Binding device sn=$sn');
await ref.read(deviceControllerProvider.notifier).bindDevice(sn);
} catch (e) {
debugPrint('[WiFi Config] bindDevice 异常: $e');
}
} }
if (!mounted) return; if (!mounted) return;
setState(() => _isBinding = false);
context.go('/device-control'); context.go('/device-control');
return; return;
} }
@ -705,7 +714,7 @@ class _WifiConfigPageState extends ConsumerState<WifiConfigPage>
} }
if (_currentStep == 4) { if (_currentStep == 4) {
showNext = true; showNext = true;
nextText = '进入设备'; nextText = _isBinding ? '绑定中...' : '进入设备';
} }
if (!showNext && _currentStep != 3) { if (!showNext && _currentStep != 3) {
@ -764,7 +773,7 @@ class _WifiConfigPageState extends ConsumerState<WifiConfigPage>
if (_currentStep < 4) const SizedBox(width: 16), if (_currentStep < 4) const SizedBox(width: 16),
GradientButton( GradientButton(
text: nextText, text: nextText,
onPressed: _handleNext, onPressed: _isBinding ? null : _handleNext,
height: 56, height: 56,
width: _currentStep == 4 ? 200 : 160, width: _currentStep == 4 ? 200 : 160,
), ),