From 281a6cc5d275a11c6b6ae2e12a2589c559cb8ab8 Mon Sep 17 00:00:00 2001 From: perol Date: Thu, 16 May 2024 23:15:17 +0800 Subject: [PATCH] caption fetch status --- ios/Podfile.lock | 4 +- lib/page/picture/illust_detail_content.dart | 33 ++++++++++++++- lib/page/picture/illust_store.dart | 45 +++++++++++++-------- 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index c9032ca21..baf78c345 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -26,7 +26,7 @@ PODS: - FlutterMacOS - permission_handler_apple (9.3.0): - Flutter - - receive_sharing_intent (1.6.8): + - receive_sharing_intent (1.8.0): - Flutter - share_plus (0.0.1): - Flutter @@ -120,7 +120,7 @@ SPEC CHECKSUMS: package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2 - receive_sharing_intent: 6837b01768e567fe8562182397bf43d63d8c6437 + receive_sharing_intent: df9c334dc9feadcbd3266e5cb49c8443405e1c9f share_plus: 8875f4f2500512ea181eef553c3e27dba5135aad shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695 sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec diff --git a/lib/page/picture/illust_detail_content.dart b/lib/page/picture/illust_detail_content.dart index a853bda80..4a466c87f 100644 --- a/lib/page/picture/illust_detail_content.dart +++ b/lib/page/picture/illust_detail_content.dart @@ -42,12 +42,14 @@ class _IllustDetailContentState extends State { late UserStore? userStore; late FocusNode _focusNode; + late IllustStore? _illustStore; String _selectedText = ""; @override void initState() { _focusNode = FocusNode(); _illusts = widget.illusts; + _illustStore = widget.illustStore; userStore = widget.userStore; super.initState(); supportTranslateCheck(); @@ -70,7 +72,7 @@ class _IllustDetailContentState extends State { _buildInfoArea(context, _illusts), _buildNameAvatar(context, _illusts), _buildTagArea(context, _illusts), - if (_illusts.caption.isNotEmpty) _buildCaptionArea(_illusts), + _buildCaptionArea(_illusts), _buildCommentTextArea(context, _illusts), Padding( padding: @@ -245,7 +247,34 @@ class _IllustDetailContentState extends State { ); } - Container _buildCaptionArea(Illusts data) { + Widget _buildCaptionArea(Illusts data) { + if (data.caption.isEmpty == true && + _illustStore?.captionFetchError == true) { + return Container( + margin: EdgeInsets.only(top: 4), + child: Container( + child: Center( + child: InkWell( + onTap: () { + _illustStore?.fetch(); + }, + child: Text("Caption fetch error,click to retry")), + ), + ), + ); + } + if (data.caption.isEmpty && _illustStore?.captionFetching == true) { + return Container( + child: Center( + child: Padding( + padding: const EdgeInsets.all(16.0), + child: CircularProgressIndicator(), + ), + )); + } + if (data.caption.isEmpty) { + return Container(height: 1); + } return Container( margin: EdgeInsets.only(top: 4), child: Padding( diff --git a/lib/page/picture/illust_store.dart b/lib/page/picture/illust_store.dart index 769a25ffe..e029e002a 100644 --- a/lib/page/picture/illust_store.dart +++ b/lib/page/picture/illust_store.dart @@ -36,13 +36,14 @@ abstract class _IllustStoreBase with Store { bool isBookmark = false; @observable String? errorMessage; - @observable int state = 0; + @observable + bool captionFetchError = false; + @observable + bool captionFetching = false; - void dispose() { - - } + void dispose() {} _IllustStoreBase(this.id, this.illusts) { isBookmark = illusts?.isBookmarked ?? false; @@ -52,27 +53,39 @@ abstract class _IllustStoreBase with Store { @action fetch() async { errorMessage = null; - if (illusts == null || illusts?.caption == null || illusts?.caption.isEmpty == true) { + if (illusts == null || + illusts?.caption == null || + illusts?.caption.isEmpty == true) { + final captionEmtpyCase = illusts != null && illusts!.caption.isEmpty; + if (captionEmtpyCase) { + captionFetching = true; + } try { Response response = await client.getIllustDetail(id); final result = Illusts.fromJson(response.data['illust']); illusts = result; isBookmark = illusts!.isBookmarked; state = illusts?.isBookmarked ?? isBookmark ? 2 : 0; + captionFetching = false; } on DioException catch (e) { - if (e.response != null) { - if (e.response!.statusCode == HttpStatus.notFound) { - errorMessage = '404 Not Found'; - return; - } - try { - errorMessage = - ErrorMessage.fromJson(e.response!.data).error.message; - } catch (e) { + captionFetching = false; + if (captionEmtpyCase) { + captionFetchError = true; + } else { + if (e.response != null) { + if (e.response!.statusCode == HttpStatus.notFound) { + errorMessage = '404 Not Found'; + return; + } + try { + errorMessage = + ErrorMessage.fromJson(e.response!.data).error.message; + } catch (e) { + errorMessage = e.toString(); + } + } else { errorMessage = e.toString(); } - } else { - errorMessage = e.toString(); } } }