Skip to content

Commit a6a0d04

Browse files
authored
Merge pull request #864 from iseruuuuu/feature/fix-share-error
シェアに関する不具合を直しました
2 parents c89b736 + daf3b78 commit a6a0d04

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/core/utils/helpers/share_helper.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dart:async';
12
import 'dart:io';
23

34
import 'package:flutter/material.dart';
@@ -14,14 +15,22 @@ class ShareHelpers {
1415
List<XFile> files,
1516
String text,
1617
) async {
17-
await Share.shareXFiles(
18-
files,
19-
text: text,
20-
);
18+
try {
19+
await Share.shareXFiles(
20+
files,
21+
text: text,
22+
).timeout(const Duration(seconds: 5));
23+
} on TimeoutException {
24+
return;
25+
}
2126
}
2227

2328
Future<void> shareOnlyPost(List<XFile> files) async {
24-
await Share.shareXFiles(files);
29+
try {
30+
await Share.shareXFiles(files).timeout(const Duration(seconds: 5));
31+
} on TimeoutException {
32+
return;
33+
}
2534
}
2635

2736
Future<void> captureAndShare({
@@ -41,11 +50,14 @@ class ShareHelpers {
4150
final filePath = '${tempDir.path}/shared_image.png';
4251
final file = File(filePath);
4352
await file.writeAsBytes(screenshotBytes);
53+
// シェア処理を実行(タイムアウト付き)
4454
if (hasText) {
4555
await sharePosts([XFile(file.path)], shareText!);
4656
} else {
4757
await shareOnlyPost([XFile(file.path)]);
4858
}
59+
} on Exception {
60+
return;
4961
} finally {
5062
loading.value = false;
5163
}

lib/ui/component/app_share_widget.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AppShareWidget extends StatelessWidget {
3737
child: CachedNetworkImage(
3838
imageUrl: supabase.storage
3939
.from('food')
40-
.getPublicUrl(posts.foodImage),
40+
.getPublicUrl(posts.firstFoodImage),
4141
fit: BoxFit.cover,
4242
),
4343
),

0 commit comments

Comments
 (0)