initialize method
Initialization.
Location information is available or not and permissions are granted.
If checkPermission
is true
, permission check is performed.
初期化を行います。
位置情報が利用可能かどうかとパーミッションの許可を行います。
checkPermission
がtrue
の場合、パーミッションチェックを行います。
Implementation
Future<void> initialize({
bool checkPermission = true,
Duration timeout = const Duration(seconds: 60),
}) async {
if (_initializeCompleter != null) {
return _initializeCompleter?.future;
}
if (initialized) {
return;
}
_initializeCompleter = Completer<void>();
try {
if (!await _location.serviceEnabled().timeout(timeout)) {
throw Exception(
"Location service not available. The platform may not be supported or it may be disabled in the settings. please confirm.",
);
}
if (checkPermission) {
if (!await requestPermission(timeout: timeout)) {
debugPrint(
"You are not authorized to use the location information service. Check the permission settings.",
);
}
}
_initialized = true;
notifyListeners();
_initializeCompleter?.complete();
_initializeCompleter = null;
} catch (e) {
_initializeCompleter?.completeError(e);
_initializeCompleter = null;
rethrow;
} finally {
_initializeCompleter?.complete();
_initializeCompleter = null;
}
}