Skip to content

Commit

Permalink
changed from device_id to device_info
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasnilsson committed Sep 26, 2020
1 parent 75c328b commit b1dc2f1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/health/example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_id","path":"/Users/tnni/.pub-cache/hosted/pub.dartlang.org/device_id-0.2.0/","dependencies":[]},{"name":"health","path":"/Users/tnni/GitHub/flutter-plugins/packages/health/","dependencies":["device_id"]}],"android":[{"name":"device_id","path":"/Users/tnni/.pub-cache/hosted/pub.dartlang.org/device_id-0.2.0/","dependencies":[]},{"name":"health","path":"/Users/tnni/GitHub/flutter-plugins/packages/health/","dependencies":["device_id"]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"device_id","dependencies":[]},{"name":"health","dependencies":["device_id"]}],"date_created":"2020-09-26 18:14:38.976965","version":"1.17.5"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info","path":"/Users/tnni/.pub-cache/hosted/pub.dartlang.org/device_info-0.4.2+8/","dependencies":[]},{"name":"health","path":"/Users/tnni/GitHub/flutter-plugins/packages/health/","dependencies":["device_info"]}],"android":[{"name":"device_info","path":"/Users/tnni/.pub-cache/hosted/pub.dartlang.org/device_info-0.4.2+8/","dependencies":[]},{"name":"health","path":"/Users/tnni/GitHub/flutter-plugins/packages/health/","dependencies":["device_info"]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"device_info","dependencies":[]},{"name":"health","dependencies":["device_info"]}],"date_created":"2020-09-26 18:28:33.667680","version":"1.17.5"}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/tnni/development/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/tnni/GitHub/flutter-plugins/packages/health/example"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_TARGET=/Users/tnni/GitHub/flutter-plugins/packages/health/example/lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=/Users/tnni/development/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "TRACK_WIDGET_CREATION=true"
export "DART_DEFINES=flutter.inspector.structuredErrors=true"
7 changes: 7 additions & 0 deletions packages/health/example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,16 @@
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../Flutter/Flutter.framework",
"${BUILT_PRODUCTS_DIR}/device_info/device_info.framework",
"${BUILT_PRODUCTS_DIR}/health/health.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/device_info.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/health.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down
2 changes: 1 addition & 1 deletion packages/health/lib/health.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ library health;
import 'dart:async';
import 'package:flutter/services.dart';
import 'dart:io' show Platform;
import 'package:device_id/device_id.dart';
import 'package:device_info/device_info.dart';

part 'package:health/src/units.dart';

Expand Down
17 changes: 10 additions & 7 deletions packages/health/lib/src/health_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ part of health;
class HealthFactory {
static const MethodChannel _channel = const MethodChannel('flutter_health');
String _deviceId;
DeviceInfoPlugin _deviceInfo = DeviceInfoPlugin();

static PlatformType _platformType =
Platform.isAndroid ? PlatformType.ANDROID : PlatformType.IOS;
Platform.isAndroid ? PlatformType.ANDROID : PlatformType.IOS;

/// Check if a given data type is available on the platform
bool _isDataTypeAvailable(HealthDataType dataType) =>
Expand All @@ -25,17 +26,17 @@ class HealthFactory {

List<String> keys = types.map((e) => _enumToString(e)).toList();
final bool isAuthorized =
await _channel.invokeMethod('requestAuthorization', {'types': keys});
await _channel.invokeMethod('requestAuthorization', {'types': keys});
return isAuthorized;
}

/// Calculate the BMI using the last observed height and weight values.
Future<List<HealthDataPoint>> _computeAndroidBMI(
DateTime startDate, DateTime endDate) async {
List<HealthDataPoint> heights =
await _prepareQuery(startDate, endDate, HealthDataType.HEIGHT);
await _prepareQuery(startDate, endDate, HealthDataType.HEIGHT);
List<HealthDataPoint> weights =
await _prepareQuery(startDate, endDate, HealthDataType.WEIGHT);
await _prepareQuery(startDate, endDate, HealthDataType.WEIGHT);

double h = heights.last.value.toDouble();

Expand Down Expand Up @@ -72,12 +73,12 @@ class HealthFactory {

if (!granted) {
String api =
_platformType == PlatformType.ANDROID ? "Google Fit" : "Apple Health";
_platformType == PlatformType.ANDROID ? "Google Fit" : "Apple Health";
throw _HealthException(types, "Permission was not granted for $api");
}
for (HealthDataType type in types) {
List<HealthDataPoint> result =
await _prepareQuery(startDate, endDate, type);
await _prepareQuery(startDate, endDate, type);
dataPoints.addAll(result);
}
return removeDuplicates(dataPoints);
Expand All @@ -88,7 +89,9 @@ class HealthFactory {
DateTime startDate, DateTime endDate, HealthDataType dataType) async {
/// Ask for device ID only once
if (_deviceId == null) {
_deviceId = await DeviceId.getID;
_deviceId = _platformType == PlatformType.ANDROID
? (await _deviceInfo.androidInfo).androidId
: (await _deviceInfo.iosInfo).identifierForVendor;
}

/// If not implemented on platform, throw an exception
Expand Down
2 changes: 1 addition & 1 deletion packages/health/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
dependencies:
flutter:
sdk: flutter
device_id: ^0.2.0
device_info: ^0.4.2+8

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit b1dc2f1

Please sign in to comment.