cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
550 stars 678 forks source link

[health 11.1.0] NullPointerException in getHealthAggregateDataFromTypes (Android Health Connect) #1083

Open koenmuilwijk opened 1 day ago

koenmuilwijk commented 1 day ago

Plugin Name

health

Plugin Version

11.1.0

Device

Android

Operating System

14

Describe the bug

There appears to be a mismatch of argument names between Flutter bridge and Kotlin code:

Compare health_plugin.dart:

  Future<List<HealthDataPoint>> _dataAggregateQuery(
      DateTime startDate,
      DateTime endDate,
      List<HealthDataType> dataTypes,
      int activitySegmentDuration,
      bool includeManualEntry) async {
    final args = <String, dynamic>{
      'dataTypeKeys': dataTypes.map((dataType) => dataType.name).toList(),
      'startTime': startDate.millisecondsSinceEpoch,
      'endTime': endDate.millisecondsSinceEpoch,
      'activitySegmentDuration': activitySegmentDuration,
      'includeManualEntry': includeManualEntry
    };

    final fetchedDataPoints =
        await _channel.invokeMethod('getAggregateData', args);

compare with Kotlin implementation:

        val dataType = call.argument<String>("dataTypeKey")!!
        val interval = call.argument<Long>("interval")!!
        val startTime = Instant.ofEpochMilli(call.argument<Long>("startTime")!!)
        val endTime = Instant.ofEpochMilli(call.argument<Long>("endTime")!!)

And note the difference in parameter names for dataTypeKey vs dataTypeKeys and also for interval vs activitySegmentDuration.

Steps to Reproduce

Calling getHealthAggregateDataFromTypes with AndroidHealthConnect raises java.lang.NullPointerException.

var aggregatedResult = await Health().getHealthAggregateDataFromTypes(
        types: [ HealthDataType.STEPS ],
        startDate: from,
        endDate: till,
        includeManualEntry: false,
        activitySegmentDuration: 3600,
      );

Expected Behavior

Return data aggregated in buckets of specified interval.

Actual Behavior

Throwing java.lang.NullPointerException

Flutter Logs

No response

Screenshots

No response

Flutter Doctor Output

[√] Flutter (Channel stable, 3.24.2, on Microsoft Windows [Version 10.0.22631.4460], locale en-NL)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[!] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.9.4)
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and
      include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK
[√] Android Studio (version 2024.1)
[√] Android Studio (version 2022.2)
[√] VS Code (version 1.92.2)
[√] Connected device (4 available)
[√] Network resources

Additional Information

No response