Android のGPS切断からの復帰処理のデバッグ
This commit is contained in:
@ -20,7 +20,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../main.dart';
|
||||
|
||||
|
||||
class IndexController extends GetxController {
|
||||
class IndexController extends GetxController with WidgetsBindingObserver {
|
||||
List<GeoJSONFeatureCollection> locations = <GeoJSONFeatureCollection>[].obs;
|
||||
List<GeoJSONFeature> currentFeature = <GeoJSONFeature>[].obs;
|
||||
List<Destination> currentDestinationFeature = <Destination>[].obs;
|
||||
@ -183,6 +183,9 @@ class IndexController extends GetxController {
|
||||
_connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
|
||||
super.onInit();
|
||||
|
||||
WidgetsBinding.instance?.addObserver(this);
|
||||
_startLocationService(); // アプリ起動時にLocationServiceを開始する
|
||||
|
||||
print('IndexController onInit called'); // デバッグ用の出力を追加
|
||||
|
||||
}
|
||||
@ -196,9 +199,48 @@ class IndexController extends GetxController {
|
||||
@override
|
||||
void onClose() {
|
||||
_connectivitySubscription.cancel();
|
||||
WidgetsBinding.instance?.removeObserver(this);
|
||||
_stopLocationService(); // アプリ終了時にLocationServiceを停止する
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
if (!_isLocationServiceRunning()) {
|
||||
_startLocationService();
|
||||
}
|
||||
} else if (state == AppLifecycleState.paused) {
|
||||
_stopLocationService();
|
||||
}
|
||||
}
|
||||
|
||||
bool _isLocationServiceRunning() {
|
||||
// LocationServiceが実行中かどうかを確認する処理を実装する
|
||||
// 例えば、SharedPreferencesにサービスの状態を保存するなど
|
||||
// ここでは簡単のために、常にfalseを返すようにしています
|
||||
return false;
|
||||
}
|
||||
|
||||
void _startLocationService() async {
|
||||
const platform = MethodChannel('location');
|
||||
try {
|
||||
await platform.invokeMethod('startLocationService');
|
||||
} on PlatformException catch (e) {
|
||||
print("Failed to start location service: '${e.message}'.");
|
||||
}
|
||||
}
|
||||
|
||||
void _stopLocationService() async {
|
||||
const platform = MethodChannel('location');
|
||||
try {
|
||||
await platform.invokeMethod('stopLocationService');
|
||||
} on PlatformException catch (e) {
|
||||
print("Failed to stop location service: '${e.message}'.");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@override
|
||||
void onReady() async {
|
||||
|
||||
Reference in New Issue
Block a user