Error: None of the following candidates is applicable because of receiver type mismatch: public operator fun <T, R> DeepRecursiveFunction<TypeVariable(T), TypeVariable(R)>.invoke(value: TypeVariable(T)): TypeVariable(R) defined in kotlin
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import android.content.Context
import androidx.health.connect.client.HealthConnectClient
import androidx.health.connect.client.PermissionController
import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod
import androidx.health.connect.client.request.AggregateGroupByPeriodRequest
import androidx.health.connect.client.records.StepsRecord
import java.time.LocalDateTime
import androidx.health.connect.client.time.TimeRangeFilter
import java.time.Period
class MainActivity: FlutterFragmentActivity() {
private val CHANNEL = "healthconnect"
private val DATA_AGGREGATION_CHANNEL = "dataAggregation"
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
if (call.method == "launchHealthApp") {
launchHealthApp()
result.success(null)
} else {
result.notImplemented()
}
}
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, DATA_AGGREGATION_CHANNEL).setMethodCallHandler { call, result ->
if (call.method == "aggregateStepsIntoMinutes") {
val start = call.argument<String>("start")
val end = call.argument<String>("end")
val average = aggregateStepsIntoMinutes(start, end)
result.success(average)
} else {
result.notImplemented()
}
}
}
private fun launchHealthApp() {
val context: Context = this
val intent = context.packageManager.getLaunchIntentForPackage("com.google.android.apps.healthdata")
if (intent !== null) {
context.startActivity(intent)
} else {
}
}
private fun aggregateStepsIntoMinutes(
start: String?,
end: String?
) {
try {
val healthConnectClient = HealthConnectClient(this)
val startTime = LocalDateTime.of(2024, 2, 1, 0, 0)
val endTime = LocalDateTime.of(2024, 2, 14, 0, 0)
val response = healthConnectClient.aggregateGroupByPeriod(
AggregateGroupByPeriodRequest(
metrics = setOf(StepsRecord.COUNT_TOTAL),
timeRangeFilter = TimeRangeFilter.between(startTime, endTime),
timeRangeSlicer = Period.ofDays(1)
)
)
for (periodResult in response) {
val totalSteps = periodResult.result[StepsRecord.COUNT_TOTAL]
}
} catch (e: Exception) {
}
}
}
Hi, I am trying to write some Kotliin for my flutter app in order to aggregate data from health connect and I am getting the described error. Thanks in advance for any help.