Files
ReelShort/lib/pages/account/account_devices_logic.dart

44 lines
1003 B
Dart

// 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<AccountDevice> devices = const [];
bool loading = false;
String? error;
bool _disposed = false;
/// 拉取当前账号的设备列表。
Future<void> 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();
}
}