Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 6 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CARP Flutter plugins

This repo contains the source code for Flutter first-party plugins developed by developers at the [Copenhagen Research Platform (CARP)](http://www.carp.dk/) at The Technical University of Denmark.
This repo contains the source code for Flutter first-party plugins maintained by the [Copenhagen Research Platform (CARP)](http://www.carp.dk/) team at the Technical University of Denmark.
Check the `packages` directory for all plugins.

Flutter plugins enable access to platform-specific APIs using a platform channel.
Expand All @@ -10,7 +10,7 @@ For more information about plugins and how to use them, see
## Plugins
These are the available plugins in this repository.

| Plugin | Description | Android | iOS | http://pub.dev/ |
| Plugin | Description | Android | iOS | pub.dev |
|--------|-------------|:-------:|:---:|:---------:|
| [screen_state](./packages/screen_state) | Track screen state changes | ✔️ | ✔️ | [![pub package](https://img.shields.io/pub/v/screen_state.svg)](https://pub.dartlang.org/packages/screen_state) |
| [light](./packages/light) | Track light sensor readings | ✔️ | ❌ | [![pub package](https://img.shields.io/pub/v/light.svg)](https://pub.dartlang.org/packages/light) |
Expand All @@ -36,18 +36,8 @@ Please check existing issues and file any new issues, bugs, or feature requests
## Contributing

As part of the open-source Flutter ecosystem, we would welcome any help in maintaining and enhancing these plugins.
We (i.e., CACHET) have limited resources for maintaining these plugins and we rely on **your** help in this.
We welcome any contribution -- from small error corrections in the documentation, to bug fixes, to large features enhacements, or even new features in a plugin.
If you wish to contribute to any of the plugins in this repo,
please review our [contribution guide](https://github.com/cph-cachet/flutter-plugins/CONTRIBUTING.md),
and send a [pull request](https://github.com/cph-cachet/flutter-plugins/pulls).


In general, if you wish to contribute a new plugin to the Flutter ecosystem, please
see the documentation for [developing packages](https://flutter.io/developing-packages/) and
[platform channels](https://flutter.io/platform-channels/). You can store
your plugin source code in any GitHub repository (the present repo is only
intended for plugins developed by the core CARP team). Once your plugin
is ready you can [publish](https://flutter.io/developing-packages/#publish)
to the [pub repository](https://pub.dartlang.org/).
We (i.e., the CARP team) have limited resources for maintaining these plugins, and we rely on **your** help in this.
We welcome any contribution - from small error corrections in the documentation, to bug fixes, to large feature enhancements, or even new features in a plugin.
If you wish to contribute to any of the plugins in this repo, please review our [contribution guide](https://github.com/cph-cachet/flutter-plugins/CONTRIBUTING.md) and send a [pull request](https://github.com/cph-cachet/flutter-plugins/pulls).


Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.health.connect.client.HealthConnectClient
import androidx.health.connect.client.records.*
import androidx.health.connect.client.records.metadata.Device
import androidx.health.connect.client.records.metadata.Metadata
import androidx.health.connect.client.response.InsertRecordsResponse
import androidx.health.connect.client.units.*
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel.Result
Expand Down Expand Up @@ -123,17 +124,31 @@ class HealthDataWriter(
val record = createRecord(type, startTime, endTime, value, metadata)

if (record == null) {
result.success(false)
result.success("")
return
}

scope.launch {
try {
healthConnectClient.insertRecords(listOf(record))
result.success(true)
// Insert records into Health Connect
val insertResponse: InsertRecordsResponse = healthConnectClient.insertRecords(listOf(record))

// Extract UUID from the first inserted record
val insertedUUID = insertResponse.recordIdsList.firstOrNull() ?: ""

if (insertedUUID.isEmpty()) {
Log.e("FLUTTER_HEALTH::ERROR", "UUID is empty! No records were inserted.")
} else {
Log.i(
"FLUTTER_HEALTH::SUCCESS",
"[Health Connect] Workout $insertedUUID was successfully added!"
)
}

result.success(insertedUUID)
} catch (e: Exception) {
Log.e("FLUTTER_HEALTH::ERROR", "Error writing $type: ${e.message}")
result.success(false)
result.success("")
}
}
}
Expand Down Expand Up @@ -161,8 +176,11 @@ class HealthDataWriter(
val workoutMetadata = buildMetadata(recordingMethod = recordingMethod, deviceType = deviceType)

if (!HealthConstants.workoutTypeMap.containsKey(type)) {
result.success(false)
Log.w("FLUTTER_HEALTH::ERROR", "[Health Connect] Workout type not supported")
result.success("")
Log.w(
"FLUTTER_HEALTH::ERROR",
"[Health Connect] Workout type not supported"
)
return
}

Expand Down Expand Up @@ -213,18 +231,31 @@ class HealthDataWriter(
),
)
}

// Insert records into Health Connect
val insertResponse: InsertRecordsResponse = healthConnectClient.insertRecords(list)

// Extract UUID from the first inserted record
val insertedUUID = insertResponse.recordIdsList.firstOrNull() ?: ""

if (insertedUUID.isEmpty()) {
Log.e("FLUTTER_HEALTH::ERROR", "UUID is empty! No records were inserted.")
}

healthConnectClient.insertRecords(list)
result.success(true)
Log.i("FLUTTER_HEALTH::SUCCESS", "[Health Connect] Workout was successfully added!")
Log.i(
"FLUTTER_HEALTH::SUCCESS",
"[Health Connect] Workout $insertedUUID was successfully added!"
)

result.success(insertedUUID)
} catch (e: Exception) {
Log.w(
"FLUTTER_HEALTH::ERROR",
"[Health Connect] There was an error adding the workout",
)
Log.w("FLUTTER_HEALTH::ERROR", e.message ?: "unknown error")
Log.w("FLUTTER_HEALTH::ERROR", e.stackTrace.toString())
result.success(false)
result.success("")
}
}
}
Expand Down
Loading