Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Health (9.0.1) - Allow individual nutrition values to be written #925

Closed
shubhamsinghmutualmobile opened this issue Mar 26, 2024 · 2 comments
Labels
bugfix a bug fix

Comments

@shubhamsinghmutualmobile
Copy link
Contributor

Device / Emulator and OS

  • Device: iPhone 11
  • OS: iOS 17.3.1

Describe the bug

After merging #924, I realised that if I want to just write the caffeine value to the health store, I would still need to pass the following values as null:

  1. caloriesConsumed
  2. carbohydrates
  3. protein
  4. fatTotal

i.e. my code would look something like this:

final wasWriteSuccessful = await health.writeMeal(
  time.subtract(const Duration(seconds: 1)),
  time,
  null,
  null,
  null,
  null,
  'Caffeine',
  caffeineVolumeGram / 1000,
  MealType.SNACK,
);

which in itself is not a problem, but in order to make this write operation successful, I would need to ask the user to provide write permissions for all data types mentioned above which is not ideal.

Ideally, if I just want to write the caffeine value, I should only need to ask for its specific permission from the user.

I would expect the API to behave in either of the following two ways:

  1. The existing writeMeal method should only consider writing values to the health store for which the user has actually granted permission(s). For example, if the user has only granted permission for caffeine, then no matter what values are being sent for caloriesConsumed, carbohydrates, protein, or fatTotal, the method writeMeal would make attempt to write the caffeine ONLY.

  2. Along with having a method that clubs all nutrition values together (like writeMeal), we could also have separate methods for individual writing (e.g. writeCaffeine, writeProtein, etc).

To Reproduce

The description should suffice

Expected behavior

Expected that the library would allow writing single nutrition values.

Actual behavior

The library clubs all nutrition values together and forces the user to grant permissions for even the values that he does NOT want to write.

Screenshots

N/A

Flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.3, on macOS 13.6.4 22G513 darwin-arm64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] Connected device (4 available)
    ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] Network resources

• No issues found!

Additional information

N/A

@shubhamsinghmutualmobile
Copy link
Contributor Author

@bardram I have added a very quick (1-liner) fix for this issue here

Could you please review it?

Apologies that I have to bother you like this. This should be the last time I do so.

@shubhamsinghmutualmobile
Copy link
Contributor Author

This is fixed with version 10.1.0 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix a bug fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant