feat(account): 增加账号中心页面逻辑
This commit is contained in:
1 parent
ef7f4ce3b6
commit
c68f02449f
6 files changed
+503
No files matched your search
@@ -0,0 +1,45 @@
|
||||
// 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
|
||||
: 'accountDevicesLoadFailed';
|
||||
} finally {
|
||||
loading = false;
|
||||
_notify();
|
||||
}
|
||||
}
|
||||
|
||||
void _notify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user