まだ#2800検証中
This commit is contained in:
@ -5,28 +5,78 @@ import 'package:geolocator/geolocator.dart';
|
||||
import 'package:rogapp/widgets/debug_widget.dart';
|
||||
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
|
||||
|
||||
// LocationControllerクラスは、GetxControllerを継承したクラスであり、位置情報の管理を担当しています。
|
||||
// LocationControllerは以下の機能を提供しています。
|
||||
// LocationControllerは、アプリ全体で位置情報を一元管理するための重要なコンポーネントです。
|
||||
// 他のコンポーネントは、LocationControllerから位置情報を取得し、位置情報に関連する機能を実装することができます。
|
||||
//
|
||||
// * 現在の位置情報を保持し、他のコンポーネントからアクセスできるようにします。
|
||||
// * 位置情報のストリームを管理し、位置情報の更新を監視します。
|
||||
// * 位置情報サービスの有効性と権限の確認を行い、適切な処理を行います。
|
||||
// * 位置情報のストリームを開始、停止、再開する機能を提供します。
|
||||
// * 位置マーカーの位置情報をStreamControllerを通じて他のコンポーネントに通知します。
|
||||
//
|
||||
class LocationController extends GetxController {
|
||||
// Reactive variable to hold the current position
|
||||
Rx<Position?> currentPosition = Rx<Position?>(null);
|
||||
Rx<Position?> currentPosition = Rx<Position?>(null);
|
||||
// 現在の位置情報を保持するReactive変数です。Rx<Position?>型で宣言されています。
|
||||
|
||||
// Subscription to the position stream
|
||||
StreamSubscription<Position>? positionStream;
|
||||
StreamSubscription<Position>? positionStream;
|
||||
// 位置情報のストリームを保持する変数です。StreamSubscription<Position>型で宣言されています。
|
||||
|
||||
final locationMarkerPositionStreamController =
|
||||
StreamController<LocationMarkerPosition?>.broadcast();
|
||||
// 位置マーカーの位置情報を送信するためのStreamControllerです。
|
||||
// StreamController<LocationMarkerPosition?>型で宣言されています。
|
||||
|
||||
bool isStreamPaused = false;
|
||||
bool isStreamPaused = false; // 位置情報のストリームが一時停止中かどうかを示すフラグです。bool型で宣言されています。
|
||||
|
||||
// ====== Akira , GPS信号強度をシミュレート ==== ここから
|
||||
//
|
||||
|
||||
// GPS信号強度をシミュレートするための変数
|
||||
Rx<String> _simulatedSignalStrength = Rx<String>('high');
|
||||
|
||||
// GPS信号強度をシミュレートするための関数
|
||||
void setSimulatedSignalStrength(String strength) {
|
||||
_simulatedSignalStrength.value = strength;
|
||||
}
|
||||
|
||||
// シミュレートされた信号強度を取得するための関数
|
||||
String getSimulatedSignalStrength() {
|
||||
return _simulatedSignalStrength.value;
|
||||
}
|
||||
|
||||
//
|
||||
// ====== Akira , GPS信号強度をシミュレート ==== ここから
|
||||
|
||||
// 位置マーカーの位置情報のストリームを取得するゲッター関数です。
|
||||
// locationMarkerPositionStreamController.streamを返します。
|
||||
//
|
||||
Stream<LocationMarkerPosition?> get locationMarkerPositionStream =>
|
||||
locationMarkerPositionStreamController.stream;
|
||||
|
||||
// コントローラーの初期化時に呼び出されるライフサイクルメソッドです。
|
||||
// startPositionStreamメソッドを呼び出して、位置情報のストリームを開始します。
|
||||
//
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
// Start listening to location updates when the controller is initialized
|
||||
startPositionStream();
|
||||
startPositionStream();
|
||||
|
||||
}
|
||||
|
||||
// 位置情報のストリームを開始するメソッドです。
|
||||
// 位置情報サービスが有効か確認し、無効な場合はダイアログを表示します。
|
||||
// 位置情報の権限を確認し、必要な権限がない場合は権限をリクエストします。
|
||||
// 既存の位置情報のストリームをキャンセルします。
|
||||
// Geolocator.getPositionStreamを使用して、新しい位置情報のストリームを開始します。
|
||||
// ストリームから受信した位置情報をlocationMarkerPositionStreamControllerに追加します。
|
||||
// エラーが発生した場合は、locationMarkerPositionStreamControllerにエラーを追加します。
|
||||
// ストリームが一時停止中の場合は、ストリームを再開します。
|
||||
//
|
||||
void startPositionStream() async {
|
||||
// Check for location service and permissions before starting the stream
|
||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
@ -138,6 +188,10 @@ class LocationController extends GetxController {
|
||||
}
|
||||
|
||||
// Method to stop the position stream
|
||||
// 位置情報のストリームを停止するメソッドです。
|
||||
// positionStreamが存在する場合、ストリームを一時停止します。
|
||||
// isStreamPausedフラグをtrueに設定します。
|
||||
//
|
||||
void stopPositionStream() {
|
||||
if (positionStream != null) {
|
||||
positionStream!.pause();
|
||||
@ -146,6 +200,10 @@ class LocationController extends GetxController {
|
||||
}
|
||||
|
||||
// Method to resume the position stream
|
||||
// 位置情報のストリームを再開するメソッドです。
|
||||
// positionStreamが存在し、ストリームが一時停止中の場合、ストリームを再開します。
|
||||
// isStreamPausedフラグをfalseに設定します。
|
||||
//
|
||||
void resumePositionStream() {
|
||||
if (positionStream != null && isStreamPaused) {
|
||||
positionStream!.resume();
|
||||
@ -153,6 +211,9 @@ class LocationController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
// コントローラーのクローズ時に呼び出されるライフサイクルメソッドです。
|
||||
// positionStreamをキャンセルします。
|
||||
//
|
||||
@override
|
||||
void onClose() {
|
||||
// Cancel the position stream subscription when the controller is closed
|
||||
|
||||
Reference in New Issue
Block a user