feat: 优化

This commit is contained in:
2026-03-23 00:43:19 +08:00
parent ae1aa21445
commit 7be22da0f0
15 changed files with 1369 additions and 1270 deletions

View File

@@ -12,6 +12,7 @@ class MarketProvider extends ChangeNotifier {
String _searchKeyword = '';
bool _isLoading = false;
String? _error;
bool _coinsLoaded = false; // 标记是否已加载
MarketProvider(this._marketService);
@@ -24,7 +25,12 @@ class MarketProvider extends ChangeNotifier {
String get searchKeyword => _searchKeyword;
/// 加载币种列表
Future<void> loadCoins() async {
Future<void> loadCoins({bool force = false}) async {
// 如果已经加载过且不是强制刷新,则跳过
if (_coinsLoaded && !force && _allCoins.isNotEmpty) {
return;
}
_isLoading = true;
_error = null;
notifyListeners();
@@ -35,6 +41,7 @@ class MarketProvider extends ChangeNotifier {
if (response.success) {
_allCoins = response.data ?? [];
_filterCoins();
_coinsLoaded = true;
} else {
_error = response.message;
}
@@ -100,6 +107,15 @@ class MarketProvider extends ChangeNotifier {
/// 刷新
Future<void> refresh() async {
await loadCoins();
await loadCoins(force: true);
}
/// 重置加载状态(用于退出登录时)
void resetLoadState() {
_coinsLoaded = false;
_allCoins = [];
_filteredCoins = [];
_error = null;
notifyListeners();
}
}