// Author: fruit.com.cn import 'package:flutter/foundation.dart'; import '../../core/data/models/account_device.dart'; import '../../core/data/remote/api_client.dart'; import '../../core/data/repositories/account_repository.dart'; /// 只读登录设备列表状态。 class AccountDevicesLogic extends ChangeNotifier { AccountDevicesLogic(this._repository); final AccountRepository _repository; List devices = const []; bool loading = false; String? error; bool _disposed = false; /// 拉取当前账号的设备列表。 Future load() async { loading = true; error = null; _notify(); try { devices = await _repository.devices(); } catch (failure) { error = failure is ApiException ? failure.message : 'networkError'; } finally { loading = false; _notify(); } } void _notify() { if (!_disposed) notifyListeners(); } @override void dispose() { _disposed = true; super.dispose(); } }