flutter-plugins icon indicating copy to clipboard operation
flutter-plugins copied to clipboard

HEALTH 8.1.0 infinite loop on Android(Only Tested for Steps and Sleep variables so far)

Open Kam5678 opened this issue 2 years ago • 0 comments

Not sure if anyone is having this issue but whenever I try to run 8.1.0 on Android, I get an infinite loop when fetching health data, using healthconnect.

Currently tested this for the following variables:

STEPS SLEEP_IN_BED SLEEP_SESSION SLEEP_ASLEEP SLEEP_AWAKE

I haven't tested other variables, but 100% can say this problem happens when fetching steps/sleep data. I tried doing a little bit of debugging and it seems like execution gets stuck for me in the following function:

await health.requestAuthorization(androidHealthPermissions, permissions: perissionsList);

To make sure this wasn't a problem with my code, I reverted back to HEALTH 8.0.0, modifying only the pubspec.yaml file and everything worked properly as expected, fetching data with no issues

[!] Flutter (Channel [user-branch], 3.13.5, on Microsoft Windows [Version 10.0.19045.3324], locale en-CA)
    ! Flutter version 3.13.5 on channel [user-branch] at C:\flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
    • Framework revision 12fccda598 (2 months ago), 2023-09-19 13:56:11 -0700
    • Engine revision bd986c5ed2
    • Dart version 3.1.2
    • DevTools version 2.25.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

Device Used: Galaxy Tab A, Android Version 11 API 33

UPDATE:

So the reason the infinite loop occurs is because I am fetching data inside a futurebuilder, and it seems like code execution doesn't actually finish, due to the health.requestAuthroization() command, causing code execution after to not continue(no breakpoint after this function was ever encountered)

In the following situations I encountered this issue:

  • Calling health.requestAuthorization() even if hasPermissions() returns true
  • Calling health.requestAuthorization() if hasPermissions() returns false, and clicking cancel on healthConnect permissions screen

Kam5678 avatar Dec 01 '23 17:12 Kam5678