未確認だが問題回避のためプッシュ
This commit is contained in:
@ -77,6 +77,9 @@ class LocationController extends GetxController {
|
||||
// エラーが発生した場合は、locationMarkerPositionStreamControllerにエラーを追加します。
|
||||
// ストリームが一時停止中の場合は、ストリームを再開します。
|
||||
//
|
||||
// 2024-4-8 Akira : See 2809
|
||||
// stopPositionStreamメソッドを追加して、既存のストリームをキャンセルするようにしました。また、ストリームが完了したらnullに設定し、エラー発生時にストリームをキャンセルするようにしました。
|
||||
//
|
||||
void startPositionStream() async {
|
||||
// Check for location service and permissions before starting the stream
|
||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
@ -161,8 +164,7 @@ class LocationController extends GetxController {
|
||||
|
||||
await positionStream?.cancel();
|
||||
|
||||
positionStream =
|
||||
Geolocator.getPositionStream(locationSettings: locationOptions).listen(
|
||||
positionStream = Geolocator.getPositionStream(locationSettings: locationOptions).listen(
|
||||
(Position? position) {
|
||||
if (position != null) {
|
||||
final LocationMarkerPosition locationMarkerPosition =
|
||||
@ -170,14 +172,18 @@ class LocationController extends GetxController {
|
||||
latitude: position.latitude,
|
||||
longitude: position.longitude,
|
||||
accuracy: position.accuracy);
|
||||
locationMarkerPositionStreamController.add(locationMarkerPosition);
|
||||
} else {
|
||||
locationMarkerPositionStreamController.add(null);
|
||||
}
|
||||
},
|
||||
onError: (e) {
|
||||
locationMarkerPositionStreamController.addError(e);
|
||||
},
|
||||
locationMarkerPositionStreamController.add(locationMarkerPosition);
|
||||
} else {
|
||||
locationMarkerPositionStreamController.add(null);
|
||||
}
|
||||
},
|
||||
onError: (e) {
|
||||
locationMarkerPositionStreamController.addError(e);
|
||||
},
|
||||
onDone: () {
|
||||
positionStream = null; // ストリームが完了したらnullに設定
|
||||
},
|
||||
cancelOnError: true // エラー発生時にストリームをキャンセル
|
||||
);
|
||||
|
||||
// Resume stream if it was paused previously
|
||||
@ -192,10 +198,14 @@ class LocationController extends GetxController {
|
||||
// positionStreamが存在する場合、ストリームを一時停止します。
|
||||
// isStreamPausedフラグをtrueに設定します。
|
||||
//
|
||||
void stopPositionStream() {
|
||||
void stopPositionStream() async {
|
||||
if (positionStream != null) {
|
||||
positionStream!.pause();
|
||||
isStreamPaused = true;
|
||||
// updated Akira 2024-4-8
|
||||
await positionStream!.cancel();
|
||||
positionStream = null;
|
||||
|
||||
//positionStream!.pause();
|
||||
//isStreamPaused = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user