Skip to content

Commit

Permalink
Make naming more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimShadyIAm committed Sep 19, 2024
1 parent 783bfba commit 09d3cdf
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions packages/health/lib/src/health_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,21 @@ class Health {

/// Configure the health plugin. Must be called before using the plugin.
Future<void> configure() async {
if (Platform.isAndroid) {
await _checkIfHealthConnectAvailable();
}

await _checkIfHealthConnectAvailableOnAndroid();
_deviceId = Platform.isAndroid
? (await _deviceInfo.androidInfo).id
: (await _deviceInfo.iosInfo).identifierForVendor;
}

Future<void> _checkIfHealthConnectAvailable() async {
Future<void> _checkIfHealthConnectAvailableOnAndroid() async {
if (!Platform.isAndroid) return;

_healthConnectSdkStatus = await getHealthConnectSdkStatus() ??
HealthConnectSdkStatus.sdkUnavailable;

if (_healthConnectSdkStatus == HealthConnectSdkStatus.sdkUnavailable || _healthConnectSdkStatus == HealthConnectSdkStatus.sdkUnavailableProviderUpdateRequired) {
if (_healthConnectSdkStatus == HealthConnectSdkStatus.sdkUnavailable ||
_healthConnectSdkStatus ==
HealthConnectSdkStatus.sdkUnavailableProviderUpdateRequired) {
throw UnsupportedError(
'Health Connect is not available on this device, prompt the user to install it using installHealthConnect.');
}
Expand Down Expand Up @@ -104,7 +103,7 @@ class Health {
List<HealthDataType> types, {
List<HealthDataAccess>? permissions,
}) async {
await _checkIfHealthConnectAvailable();
await _checkIfHealthConnectAvailableOnAndroid();
if (permissions != null && permissions.length != types.length) {
throw ArgumentError(
"The lists of types and permissions must be of same length.");
Expand All @@ -130,7 +129,7 @@ class Health {
/// NOTE: The app must be completely killed and restarted for the changes to take effect.
/// Not implemented on iOS as there is no way to programmatically remove access.
Future<void> revokePermissions() async {
await _checkIfHealthConnectAvailable();
await _checkIfHealthConnectAvailableOnAndroid();
try {
if (Platform.isIOS) {
throw UnsupportedError(
Expand Down Expand Up @@ -203,7 +202,7 @@ class Health {
List<HealthDataType> types, {
List<HealthDataAccess>? permissions,
}) async {
await _checkIfHealthConnectAvailable();
await _checkIfHealthConnectAvailableOnAndroid();
if (permissions != null && permissions.length != types.length) {
throw ArgumentError(
'The length of [types] must be same as that of [permissions].');
Expand Down Expand Up @@ -332,7 +331,7 @@ class Health {
DateTime? endTime,
RecordingMethod recordingMethod = RecordingMethod.automatic,
}) async {
await _checkIfHealthConnectAvailable();
await _checkIfHealthConnectAvailableOnAndroid();
if (Platform.isIOS &&
[RecordingMethod.active, RecordingMethod.unknown]
.contains(recordingMethod)) {
Expand Down Expand Up @@ -408,7 +407,7 @@ class Health {
required DateTime startTime,
DateTime? endTime,
}) async {
await _checkIfHealthConnectAvailable();
await _checkIfHealthConnectAvailableOnAndroid();
endTime ??= startTime;
if (startTime.isAfter(endTime)) {
throw ArgumentError("startTime must be equal or earlier than endTime");
Expand Down Expand Up @@ -444,7 +443,7 @@ class Health {
DateTime? endTime,
RecordingMethod recordingMethod = RecordingMethod.automatic,
}) async {
await _checkIfHealthConnectAvailable();
await _checkIfHealthConnectAvailableOnAndroid();
if (Platform.isIOS &&
[RecordingMethod.active, RecordingMethod.unknown]
.contains(recordingMethod)) {
Expand Down Expand Up @@ -485,7 +484,7 @@ class Health {
DateTime? endTime,
RecordingMethod recordingMethod = RecordingMethod.automatic,
}) async {
await _checkIfHealthConnectAvailable();
await _checkIfHealthConnectAvailableOnAndroid();
if (Platform.isIOS &&
[RecordingMethod.active, RecordingMethod.unknown]
.contains(recordingMethod)) {
Expand Down Expand Up @@ -619,7 +618,7 @@ class Health {
double? zinc,
RecordingMethod recordingMethod = RecordingMethod.automatic,
}) async {
await _checkIfHealthConnectAvailable();
await _checkIfHealthConnectAvailableOnAndroid();
if (Platform.isIOS &&
[RecordingMethod.active, RecordingMethod.unknown]
.contains(recordingMethod)) {
Expand Down Expand Up @@ -700,7 +699,7 @@ class Health {
required bool isStartOfCycle,
RecordingMethod recordingMethod = RecordingMethod.automatic,
}) async {
await _checkIfHealthConnectAvailable();
await _checkIfHealthConnectAvailableOnAndroid();
if (Platform.isIOS &&
[RecordingMethod.active, RecordingMethod.unknown]
.contains(recordingMethod)) {
Expand Down Expand Up @@ -831,7 +830,7 @@ class Health {
required DateTime endTime,
List<RecordingMethod> recordingMethodsToFilter = const [],
}) async {
await _checkIfHealthConnectAvailable();
await _checkIfHealthConnectAvailableOnAndroid();
List<HealthDataPoint> dataPoints = [];

for (var type in types) {
Expand All @@ -857,7 +856,7 @@ class Health {
required List<HealthDataType> types,
required int interval,
List<RecordingMethod> recordingMethodsToFilter = const []}) async {
await _checkIfHealthConnectAvailable();
await _checkIfHealthConnectAvailableOnAndroid();
List<HealthDataPoint> dataPoints = [];

for (var type in types) {
Expand All @@ -877,7 +876,7 @@ class Health {
int activitySegmentDuration = 1,
bool includeManualEntry = true,
}) async {
await _checkIfHealthConnectAvailable();
await _checkIfHealthConnectAvailableOnAndroid();
List<HealthDataPoint> dataPoints = [];

final result = await _prepareAggregateQuery(
Expand Down Expand Up @@ -1125,7 +1124,7 @@ class Health {
String? title,
RecordingMethod recordingMethod = RecordingMethod.automatic,
}) async {
await _checkIfHealthConnectAvailable();
await _checkIfHealthConnectAvailableOnAndroid();
if (Platform.isIOS &&
[RecordingMethod.active, RecordingMethod.unknown]
.contains(recordingMethod)) {
Expand Down

0 comments on commit 09d3cdf

Please sign in to comment.