20240903 pre release
This commit is contained in:
@ -311,7 +311,7 @@ class CameraPage extends StatelessWidget {
|
||||
? ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
|
||||
onPressed: () async {
|
||||
await destinationController.makeCheckin(destination, true,
|
||||
await destinationController.makeCheckin(destination, true, // チェクインボタン
|
||||
destinationController.photos[0].path);
|
||||
if( destinationController.isInRog.value==true ) {
|
||||
destinationController.rogainingCounted.value = true; // ロゲ開始後のみ許可
|
||||
@ -526,7 +526,7 @@ class CameraPage extends StatelessWidget {
|
||||
// print(
|
||||
|
||||
// "##### current destination ${indexController.currentDestinationFeature[0].sub_loc_id} #######");
|
||||
await destinationController.makeCheckin(
|
||||
await destinationController.makeCheckin( // チェックイン確定
|
||||
indexController.currentDestinationFeature[0],
|
||||
true,
|
||||
destinationController.photos[0].path);
|
||||
@ -551,7 +551,7 @@ class CameraPage extends StatelessWidget {
|
||||
|
||||
Navigator.of(context).pop(true); // ここを修正
|
||||
},
|
||||
child: const Text("チェックイン"))
|
||||
child: const Text("チェックイン確定"))
|
||||
: Container())
|
||||
],
|
||||
);
|
||||
|
||||
@ -526,7 +526,7 @@ class DestinationController extends GetxController {
|
||||
debugPrint("** 自動チェックインの場合");
|
||||
//print(
|
||||
// "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ make checkin ${d.sub_loc_id}@@@@@@@@@@@");
|
||||
makeCheckin(d, true, ""); // チェックインして
|
||||
makeCheckin(d, true, ""); // 自動チェックイン
|
||||
//if (d.cp != -1 && d.cp != -2 && d.cp != 0 ) {
|
||||
// rogainingCounted.value = true; // ゴール用チェックイン済み
|
||||
//}
|
||||
@ -750,9 +750,11 @@ class DestinationController extends GetxController {
|
||||
}
|
||||
|
||||
int? latgoal = await db.latestGoal();
|
||||
lastGoalAt = DateTime.fromMicrosecondsSinceEpoch(latgoal!);
|
||||
debugPrint("===== last goal : $lastGoalAt =====");
|
||||
if( latgoal != null ) {
|
||||
lastGoalAt = DateTime.fromMicrosecondsSinceEpoch(latgoal!);
|
||||
debugPrint("===== last goal : $lastGoalAt =====");
|
||||
dbService.updateDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
// すべての目的地を削除する関数です。
|
||||
@ -835,7 +837,7 @@ class DestinationController extends GetxController {
|
||||
print("---- f- checkin ${d.sub_loc_id} ----");
|
||||
if (autoCheckin) {
|
||||
if (!checkingIn) {
|
||||
makeCheckin(d, true, "");
|
||||
makeCheckin(d, true, ""); // callforCheckin
|
||||
if (d.cp != -1 && d.cp != 0 && d.cp != -2) {
|
||||
rogainingCounted.value = true;
|
||||
}
|
||||
@ -1085,12 +1087,13 @@ class DestinationController extends GetxController {
|
||||
// ロゲイニングにデータを追加する関数です。
|
||||
//
|
||||
void addToRogaining(double lat, double lon, int destinationId) async {
|
||||
debugPrint("addToRogaining .... ");
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
List<Destination> d = await db.getDestinationById(destinationId);
|
||||
if (d.isEmpty) {
|
||||
Destination df = festuretoDestination(indexController.currentFeature[0]);
|
||||
//print("--- made checkin ${df.location_id} ----");
|
||||
makeCheckin(df, true, "");
|
||||
makeCheckin(df, true, ""); // addToRogaining
|
||||
}
|
||||
isInRog.value = true;
|
||||
|
||||
@ -1138,10 +1141,10 @@ class DestinationController extends GetxController {
|
||||
|
||||
// ギャラリーにも保存
|
||||
//await ImageGallerySaver.saveFile(savedImage.path);
|
||||
await Future.delayed(const Duration(seconds: 3), () async {
|
||||
await Future.delayed(const Duration(seconds: 5), () async {
|
||||
final result = await ImageGallerySaver.saveFile(savedImage.path);
|
||||
print("Save result: $result");
|
||||
}).timeout(const Duration(seconds: 5));
|
||||
}).timeout(const Duration(seconds: 7));
|
||||
|
||||
|
||||
debugPrint('Image saved to: ${savedImage.path}');
|
||||
@ -1214,14 +1217,16 @@ class DestinationController extends GetxController {
|
||||
// print(
|
||||
// "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${destination.sub_loc_id}@@@@@@@@@@@");
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
List<Destination> ddd =
|
||||
await db.getDestinationByLatLon(destination.lat!, destination.lon!);
|
||||
List<Destination> ddd = await db.getDestinationByLatLon(destination.lat!, destination.lon!);
|
||||
|
||||
if (ddd.isEmpty) {
|
||||
destination.checkedin = true;
|
||||
debugPrint("...近くにCPがないのにチェックイン?...makeCheckin imageUrl = $imageurl");
|
||||
if (imageurl.isNotEmpty) {
|
||||
String? savedImagePath = await _saveImageToGallery(imageurl);
|
||||
destination.checkin_image = savedImagePath ?? imageurl;
|
||||
}else{
|
||||
debugPrint("makeCheckin ... No image...");
|
||||
}
|
||||
await db.insertDestination(destination);
|
||||
// print("~~~~ inserted into db ~~~~");
|
||||
@ -1229,15 +1234,18 @@ class DestinationController extends GetxController {
|
||||
|
||||
if (imageurl.isEmpty) {
|
||||
if (photos.isNotEmpty) {
|
||||
debugPrint("imageurlが空の場合は、destinationのcheckin_imageプロパティを使用する");
|
||||
// imageurlが空の場合は、destinationのcheckin_imageプロパティを使用する
|
||||
debugPrint("photos = $photos");
|
||||
imageurl = photos[0].path;
|
||||
//debugPrint("photos = $photos");
|
||||
//imageurl = photos[0].path;
|
||||
}
|
||||
debugPrint("imageurl = $imageurl");
|
||||
//await _saveImageFromPath(imageurl!);
|
||||
}
|
||||
if (imageurl.isNotEmpty) {
|
||||
debugPrint("...これでアルバム保存...makeCheckin imageUrl = $imageurl");
|
||||
String? savedImagePath = await _saveImageToGallery(imageurl);
|
||||
debugPrint("イメージのアルバム保存完了!!");
|
||||
destination.checkin_image = savedImagePath ?? imageurl;
|
||||
}
|
||||
|
||||
|
||||
@ -96,6 +96,8 @@ class IndexController extends GetxController with WidgetsBindingObserver {
|
||||
|
||||
final selectedEventName = 'add_location'.tr.obs;
|
||||
|
||||
RxBool isLoadingLocations = true.obs;
|
||||
|
||||
void setSelectedEventName(String eventName) {
|
||||
selectedEventName.value = eventName;
|
||||
}
|
||||
@ -256,6 +258,9 @@ class IndexController extends GetxController with WidgetsBindingObserver {
|
||||
|
||||
tz.initializeTimeZones();
|
||||
//teamController = Get.find<TeamController>();
|
||||
|
||||
loadLocations();
|
||||
|
||||
}catch(e,stacktrace){
|
||||
print('Error in IndexController.onInit: $e');
|
||||
print('Stack trace: $stacktrace');
|
||||
@ -265,6 +270,20 @@ class IndexController extends GetxController with WidgetsBindingObserver {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadLocations() async {
|
||||
isLoadingLocations.value = true;
|
||||
try {
|
||||
await waitForMapControllerReady();
|
||||
String eventCode = currentUser.isNotEmpty ? currentUser[0]["user"]["event_code"] ?? "" : "";
|
||||
await loadLocationsBound(eventCode);
|
||||
} catch (e) {
|
||||
print('Error loading locations: $e');
|
||||
// エラーハンドリングを追加(例:スナックバーでユーザーに通知)
|
||||
} finally {
|
||||
isLoadingLocations.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
void _updateConnectionStatus(List<ConnectivityResult> results) {
|
||||
|
||||
final result = results.isNotEmpty ? results.first : ConnectivityResult.none;
|
||||
@ -873,7 +892,7 @@ class IndexController extends GetxController with WidgetsBindingObserver {
|
||||
// 要検討:Future.delayedを使用して非同期処理を待たずに先に進むようにしていますが、
|
||||
// これによってメモリリークが発生する可能性があります。非同期処理の結果を適切に処理することを検討してください。
|
||||
//
|
||||
void loadLocationsBound(String eventCode) async {
|
||||
Future<void> loadLocationsBound(String eventCode) async {
|
||||
if (isCustomAreaSelected.value == true) {
|
||||
return;
|
||||
}
|
||||
@ -881,6 +900,19 @@ class IndexController extends GetxController with WidgetsBindingObserver {
|
||||
// MapControllerの初期化が完了するまで待機
|
||||
await waitForMapControllerReady();
|
||||
|
||||
// null チェックを追加
|
||||
if (mapController.bounds == null) {
|
||||
print("MapController bounds are null");
|
||||
return;
|
||||
}
|
||||
|
||||
// バウンドが有効かどうかを確認する
|
||||
LatLngBounds bounds = mapController.bounds!;
|
||||
if (!_isValidBounds(bounds)) {
|
||||
print("MapController bounds are not valid");
|
||||
return;
|
||||
}
|
||||
|
||||
locations.clear();
|
||||
String cat = currentCat.isNotEmpty ? currentCat[0] : "";
|
||||
if (currentCat.isNotEmpty && currentCat[0] == "-all-") {
|
||||
@ -896,7 +928,7 @@ class IndexController extends GetxController with WidgetsBindingObserver {
|
||||
//
|
||||
*/
|
||||
|
||||
LatLngBounds bounds = mapController.bounds!;
|
||||
//LatLngBounds bounds = mapController.bounds!;
|
||||
|
||||
currentBound.clear();
|
||||
currentBound.add(bounds);
|
||||
@ -987,6 +1019,15 @@ class IndexController extends GetxController with WidgetsBindingObserver {
|
||||
|
||||
}
|
||||
|
||||
// バウンドが有効かどうかを確認するヘルパーメソッド
|
||||
bool _isValidBounds(LatLngBounds bounds) {
|
||||
// 緯度と経度が有効な範囲内にあるかチェック
|
||||
return bounds.southWest.latitude.abs() <= 90 &&
|
||||
bounds.southWest.longitude.abs() <= 180 &&
|
||||
bounds.northEast.latitude.abs() <= 90 &&
|
||||
bounds.northEast.longitude.abs() <= 180 &&
|
||||
bounds.southWest.latitude < bounds.northEast.latitude;
|
||||
}
|
||||
|
||||
//===Akira 追加:2024-4-6 #2800
|
||||
// 要検討:MapControllerの初期化が完了するまで待機していますが、タイムアウトを設定することを検討してください。
|
||||
|
||||
@ -8,6 +8,8 @@ import 'package:gifunavi/widgets/list_widget.dart';
|
||||
import 'package:gifunavi/widgets/map_widget.dart';
|
||||
import 'package:gifunavi/utils/location_controller.dart';
|
||||
|
||||
import '../permission/permission.dart';
|
||||
|
||||
// index_page.dartファイルの主な内容です。
|
||||
// このファイルは、アプリのメインページのUIを構築し、各機能へのナビゲーションを提供しています。
|
||||
// また、IndexControllerとDestinationControllerを使用して、状態管理と各種機能の実装を行っています。
|
||||
@ -36,12 +38,20 @@ class _IndexPageState extends State<IndexPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
//checkLoginAndShowDialog();
|
||||
//checkEventAndNavigate();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
await _ensureControllersAreInitialized();
|
||||
await PermissionController.checkAndRequestPermissions();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _ensureControllersAreInitialized() async {
|
||||
while (!Get.isRegistered<IndexController>() ||
|
||||
!Get.isRegistered<DestinationController>() ||
|
||||
!Get.isRegistered<LocationController>()) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
|
||||
void checkEventAndNavigate() async {
|
||||
if (indexController.currentUser.isNotEmpty &&
|
||||
indexController.currentUser[0]["user"]["event_code"] == null) {
|
||||
|
||||
@ -126,28 +126,27 @@ class PermissionController {
|
||||
_isRequestingPermission = true;
|
||||
_permissionCompleter = Completer<bool>();
|
||||
|
||||
bool hasPermissions = await _checkLocationPermissions();
|
||||
if (!hasPermissions) {
|
||||
bool userAgreed = await showLocationDisclosure();
|
||||
if (userAgreed) {
|
||||
try {
|
||||
await requestAllLocationPermissions();
|
||||
hasPermissions = await _checkLocationPermissions();
|
||||
} catch (e) {
|
||||
print('Error requesting location permissions: $e');
|
||||
try {
|
||||
bool hasPermissions = await _checkLocationPermissions();
|
||||
if (!hasPermissions) {
|
||||
bool userAgreed = await showLocationDisclosure();
|
||||
if (userAgreed) {
|
||||
hasPermissions = await _requestAllLocationPermissions();
|
||||
} else {
|
||||
print('User did not agree to location usage');
|
||||
hasPermissions = false;
|
||||
// アプリを終了
|
||||
SystemNavigator.pop();
|
||||
}
|
||||
} else {
|
||||
print('User did not agree to location usage');
|
||||
hasPermissions = false;
|
||||
// アプリを終了
|
||||
SystemNavigator.pop();
|
||||
}
|
||||
|
||||
_isRequestingPermission = false;
|
||||
_permissionCompleter!.complete(hasPermissions);
|
||||
} catch( e ) {
|
||||
print('Error in permission request: $e');
|
||||
_isRequestingPermission = false;
|
||||
_permissionCompleter!.complete(false);
|
||||
}
|
||||
|
||||
_isRequestingPermission = false;
|
||||
_permissionCompleter!.complete(hasPermissions);
|
||||
|
||||
debugPrint("Finish checkAndRequestPermissions...");
|
||||
return _permissionCompleter!.future;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user