flutter-plugins
flutter-plugins copied to clipboard
Health (9.0.1) - Allow individual nutrition values to be written
Device / Emulator and OS
- Device: iPhone 11
- OS: iOS 17.3.1
Describe the bug
After merging https://github.com/cph-cachet/flutter-plugins/pull/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:
- caloriesConsumed
- carbohydrates
- protein
- 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:
-
The existing
writeMealmethod 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 forcaffeine, then no matter what values are being sent forcaloriesConsumed,carbohydrates,protein, orfatTotal, the methodwriteMealwould make attempt to write thecaffeineONLY. -
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
@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.
This is fixed with version 10.1.0 👍