feat: A3 数据层 AppCatalogController(feed/详情/分类加载,供页面切换)
This commit is contained in:
1 parent
88a401512d
commit
070ec78668
2 files changed
+47
No files matched your search
@@ -0,0 +1,39 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../models/app_catalog.dart';
|
||||
import '../repositories/http_catalog_repository.dart';
|
||||
|
||||
/// 首页/发现页 feed 状态(A3 数据层)。
|
||||
class AppCatalogController extends ChangeNotifier {
|
||||
AppCatalogController(this._repository);
|
||||
|
||||
final HttpCatalogRepository _repository;
|
||||
|
||||
AppFeed? feed;
|
||||
bool loading = false;
|
||||
String? error;
|
||||
|
||||
Future<void> loadFeed() async {
|
||||
loading = true;
|
||||
error = null;
|
||||
notifyListeners();
|
||||
try {
|
||||
feed = await _repository.fetchHomeFeed();
|
||||
} catch (e) {
|
||||
error = e.toString();
|
||||
} finally {
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<AppDramaDetail> loadDetail(int id) {
|
||||
return _repository.fetchDramaDetail(id);
|
||||
}
|
||||
|
||||
Future<List<AppCategory>> loadCategories() {
|
||||
return _repository.fetchCategories();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user