ギャラリーに写真保存ができなくなったバグを修正
This commit is contained in:
@ -9,6 +9,7 @@ import 'package:geolocator/geolocator.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:latlong2/latlong.dart';
|
import 'package:latlong2/latlong.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:rogapp/main.dart';
|
import 'package:rogapp/main.dart';
|
||||||
import 'package:rogapp/model/destination.dart';
|
import 'package:rogapp/model/destination.dart';
|
||||||
import 'package:rogapp/model/gps_data.dart';
|
import 'package:rogapp/model/gps_data.dart';
|
||||||
@ -1071,6 +1072,49 @@ class DestinationController extends GetxController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _saveImageToGallery(String imagePath) async {
|
||||||
|
final status = await Permission.storage.status;
|
||||||
|
if (!status.isGranted) {
|
||||||
|
final result = await Permission.storage.request();
|
||||||
|
if (!result.isGranted) {
|
||||||
|
// ユーザーがストレージの権限を拒否した場合の処理
|
||||||
|
showDialog(
|
||||||
|
context: Get.context!,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text('ストレージの権限が必要です'),
|
||||||
|
content: Text(
|
||||||
|
'画像をギャラリーに保存するには、ストレージの権限が必要です。アプリの設定画面で権限を許可してください。'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
child: Text('キャンセル'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
child: Text('設定'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
openAppSettings(); // アプリの設定画面を開く
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
final result = await ImageGallerySaver.saveFile(imagePath);
|
||||||
|
print('Image saved to gallery: $result');
|
||||||
|
} catch (e) {
|
||||||
|
print('Failed to save image to gallery: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 買い物ポイントを作成する関数です。 指定された目的地に対して買い物ポイントの処理を行います。
|
// 買い物ポイントを作成する関数です。 指定された目的地に対して買い物ポイントの処理を行います。
|
||||||
//
|
//
|
||||||
// 買い物ポイントの作成に失敗した場合のエラーハンドリングを追加することを検討してください。
|
// 買い物ポイントの作成に失敗した場合のエラーハンドリングを追加することを検討してください。
|
||||||
@ -1079,7 +1123,8 @@ class DestinationController extends GetxController {
|
|||||||
DatabaseHelper db = DatabaseHelper.instance;
|
DatabaseHelper db = DatabaseHelper.instance;
|
||||||
await db.updateBuyPoint(destination, imageurl);
|
await db.updateBuyPoint(destination, imageurl);
|
||||||
populateDestinations();
|
populateDestinations();
|
||||||
await _saveImageFromPath(imageurl);
|
//await _saveImageFromPath(imageurl);
|
||||||
|
await _saveImageToGallery(imageurl);
|
||||||
|
|
||||||
if (indexController.currentUser.isNotEmpty) {
|
if (indexController.currentUser.isNotEmpty) {
|
||||||
double cpNum = destination.cp!;
|
double cpNum = destination.cp!;
|
||||||
@ -1135,7 +1180,10 @@ class DestinationController extends GetxController {
|
|||||||
imageurl = photos[0].path;
|
imageurl = photos[0].path;
|
||||||
}
|
}
|
||||||
debugPrint("imageurl = ${imageurl}");
|
debugPrint("imageurl = ${imageurl}");
|
||||||
await _saveImageFromPath(imageurl!);
|
//await _saveImageFromPath(imageurl!);
|
||||||
|
}
|
||||||
|
if (imageurl.isNotEmpty) {
|
||||||
|
await _saveImageToGallery(imageurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
populateDestinations();
|
populateDestinations();
|
||||||
|
|||||||
Reference in New Issue
Block a user