Skip to content

Commit

Permalink
caption fetch status
Browse files Browse the repository at this point in the history
  • Loading branch information
Notsfsssf committed May 16, 2024
1 parent 14efab8 commit 281a6cc
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 20 deletions.
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
33 changes: 31 additions & 2 deletions lib/page/picture/illust_detail_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ class _IllustDetailContentState extends State<IllustDetailContent> {

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();
Expand All @@ -70,7 +72,7 @@ class _IllustDetailContentState extends State<IllustDetailContent> {
_buildInfoArea(context, _illusts),
_buildNameAvatar(context, _illusts),
_buildTagArea(context, _illusts),
if (_illusts.caption.isNotEmpty) _buildCaptionArea(_illusts),
_buildCaptionArea(_illusts),
_buildCommentTextArea(context, _illusts),
Padding(
padding:
Expand Down Expand Up @@ -245,7 +247,34 @@ class _IllustDetailContentState extends State<IllustDetailContent> {
);
}

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(
Expand Down
45 changes: 29 additions & 16 deletions lib/page/picture/illust_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
}
Expand Down

0 comments on commit 281a6cc

Please sign in to comment.