krokyze / FitKit

Flutter plugin for reading health and fitness data. Wraps HealthKit on iOS and GoogleFit on Android.
BSD 2-Clause "Simplified" License
98 stars 72 forks source link

New datatypes in v1.1.1 have broken compatibility w/ older versions of iOS #36

Closed carlleeswanson closed 4 years ago

carlleeswanson commented 4 years ago

The addition of "STAND_TIME" appears to have made this package incompatible with iOS 12.4 (presumably other older iOS versions also).

FitKit.requestPermissions(DataType.values) always throws the following error: PlatformException(FitKit, Error type "stand time" is not supported, null)

Removing "STAND_TIME" from fit_kit.dart solves the problem. Oddly, "EXERCISE_TIME" doesn't generate an error.

MelanieGravel commented 4 years ago

I got the exact same error.

HKQuantityTypeIdentifier' has no member 'appleStandTime', on the Extensions.swift file

softmarshmallow commented 4 years ago

Also android raises error with the same comment. STAND_TIME

janosdupai commented 4 years ago

Same here.

PlatformException(FitKit, type stand_time is not supported, null) - on Android device. Any idea?

khmurakami commented 4 years ago

@janosdupai @softmarshmallow @carlleeswanson

In the example folder it has this line,

permissions = await FitKit.requestPermissions(DataType.values);

It doesn't work on Android because Standtime is not supported. The README.md shows the supported types.

DataType.values is a List of all the possible values which includes the ones supported in iOS.

The way to go about this, is to declare a new list and then pass in these values instead for Android.

  List<DataType> androidValues = [
    DataType.ENERGY,
    //DataType.EXERCISE_TIME,
    DataType.DISTANCE,
    DataType.STEP_COUNT,
    DataType.WATER,
    DataType.WEIGHT,
    DataType.HEIGHT,
    DataType.HEART_RATE,
    //DataType.STAND_TIME,
  ];

permissions = await FitKit.requestPermissions(androidValues);
krokyze commented 4 years ago

Starting from version 1.1.2 it's advised to wrap all read methods inside try catch as FitKit.read will throw specific UnsupportedException

void read() async {
  try {
    final results = await FitKit.read(
      DataType.HEART_RATE,
      dateFrom: DateTime.now().subtract(Duration(days: 5)),
      dateTo: DateTime.now(),
    );
  } on UnsupportedException catch (e) {
    // thrown in case e.dataType is unsupported
  }
}