// Author: fruit.com.cn import 'package:flutter/foundation.dart'; import '../../core/data/models/account_export.dart'; import '../../core/data/remote/api_client.dart'; import '../../core/data/repositories/account_repository.dart'; /// 账号数据导出状态与复制动作。 class AccountExportLogic extends ChangeNotifier { AccountExportLogic(this._repository, {required this.copyText}); final AccountRepository _repository; final Future Function(String text) copyText; AccountExport? data; bool loading = false; String? error; bool _disposed = false; /// 加载完整导出数据。 Future load() async { loading = true; error = null; _notify(); try { data = await _repository.export(); } catch (failure) { error = failure is ApiException ? failure.message : 'networkError'; } finally { loading = false; _notify(); } } /// 把后端下发的完整 JSON 写入剪贴板。 Future copy() async { final current = data; if (current == null) return false; await copyText(current.rawJson); return true; } void _notify() { if (!_disposed) notifyListeners(); } @override void dispose() { _disposed = true; super.dispose(); } }