feat(flutter): 增加目录加载诊断与前台重试
This commit is contained in:
1 parent
d68734cdab
commit
730a96559b
10 files changed
+268
-16
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../config/app_config.dart';
|
||||
import '../models/drama.dart';
|
||||
import '../models/home_feed.dart';
|
||||
import '../repositories/catalog_repository.dart';
|
||||
@@ -22,6 +23,7 @@ class CatalogController extends ChangeNotifier {
|
||||
/// 第一次首页请求结束后为 true。之后的重试不再回到开屏。
|
||||
bool settled = false;
|
||||
String? error;
|
||||
String? debugError;
|
||||
|
||||
List<Drama> get dramas => feed.dramas;
|
||||
List<FeedBanner> get banners => feed.banners;
|
||||
@@ -30,13 +32,18 @@ class CatalogController extends ChangeNotifier {
|
||||
Future<void> load() async {
|
||||
loading = true;
|
||||
error = null;
|
||||
debugError = null;
|
||||
notifyListeners();
|
||||
try {
|
||||
feed = await repository.fetchHomeFeed();
|
||||
} on ApiException catch (exception) {
|
||||
error = exception.message;
|
||||
} catch (_) {
|
||||
debugError = exception.toString();
|
||||
_logFailure(exception);
|
||||
} catch (exception) {
|
||||
error = 'catalogError';
|
||||
debugError = exception.toString();
|
||||
_logFailure(exception);
|
||||
} finally {
|
||||
loading = false;
|
||||
settled = true;
|
||||
@@ -52,11 +59,18 @@ class CatalogController extends ChangeNotifier {
|
||||
feed = await repository.fetchHomeFeed();
|
||||
notifyListeners();
|
||||
return true;
|
||||
} catch (_) {
|
||||
} catch (exception) {
|
||||
_logFailure(exception);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void _logFailure(Object error) {
|
||||
if (kDebugMode) {
|
||||
debugPrint('[catalog] base=${AppConfig.apiBaseUrl} error=$error');
|
||||
}
|
||||
}
|
||||
|
||||
/// 需要完整剧集时补一次详情;已加载过则直接返回,避免重复请求。
|
||||
Future<Drama> requireDetail(Drama drama) async {
|
||||
if (drama.detailLoaded) return drama;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import '../../config/app_config.dart';
|
||||
|
||||
/// 重新探测服务地址后再加载指定目录数据。
|
||||
Future<void> retryCatalogLoad({
|
||||
required Future<void> Function() reload,
|
||||
Future<void> Function()? probe,
|
||||
}) async {
|
||||
await (probe ?? AppConfig.probeAndApplyBaseUrl)();
|
||||
await reload();
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../config/app_config.dart';
|
||||
import '../models/content_category.dart';
|
||||
import '../models/drama.dart';
|
||||
import '../models/home_feed.dart';
|
||||
@@ -17,6 +18,7 @@ class CategoryController extends ChangeNotifier {
|
||||
HomeFeed feed = const HomeFeed();
|
||||
bool loading = false;
|
||||
String? error;
|
||||
String? debugError;
|
||||
bool _disposed = false;
|
||||
|
||||
/// 分类九宫格点击后读取该分类的剧目;缺失分区返回空列表。
|
||||
@@ -32,6 +34,7 @@ class CategoryController extends ChangeNotifier {
|
||||
Future<void> load() async {
|
||||
loading = true;
|
||||
error = null;
|
||||
debugError = null;
|
||||
_notify();
|
||||
try {
|
||||
final results = await Future.wait<Object>([
|
||||
@@ -40,8 +43,12 @@ class CategoryController extends ChangeNotifier {
|
||||
]);
|
||||
categories = results[0] as List<ContentCategory>;
|
||||
feed = results[1] as HomeFeed;
|
||||
} catch (_) {
|
||||
} catch (exception) {
|
||||
error = 'categoriesError';
|
||||
debugError = exception.toString();
|
||||
if (kDebugMode) {
|
||||
debugPrint('[catalog] base=${AppConfig.apiBaseUrl} error=$exception');
|
||||
}
|
||||
} finally {
|
||||
loading = false;
|
||||
_notify();
|
||||
|
||||
Reference in new issue
Block a user