cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
555 stars 682 forks source link

[HEALTH 8.1.0] - Null pointer exception in hasPermissionsHC method #878

Closed bardram closed 10 months ago

bardram commented 10 months ago

Device and OS

When calling the hasPermissions method, there is a PlatformException in Flutter wich comes from a NullPointerException in Kotlin:

E/flutter (29560): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, null, null, java.lang.NullPointerException
E/flutter (29560):  at cachet.plugins.health.HealthPlugin.hasPermissionsHC(HealthPlugin.kt:1598)

Trying to collect these health data types:

    // Define which health types to collect.
    var healthDataTypes = [
      HealthDataType.DISTANCE_WALKING_RUNNING,
      HealthDataType.EXERCISE_TIME,
      HealthDataType.STEPS,
      HealthDataType.BASAL_ENERGY_BURNED,
      HealthDataType.WEIGHT,
      HealthDataType.SLEEP_SESSION,
    ];
bardram commented 10 months ago

I've now found why this happens. It's because I add

    HealthDataType.DISTANCE_WALKING_RUNNING,
    HealthDataType.EXERCISE_TIME,

to the list - but these two data types are not supported on Health Connect. So - when removing them, it works.

However - it might be useful with more telling error messages than a null pointer exception.