Coder Social home page Coder Social logo

Comments (1)

Mravuri96 avatar Mravuri96 commented on July 17, 2024

@kvs-coder I was able to fix this in this repo. But since Workout.make always overwrites the uuid, the quantities can never be added to an already existing workout. I am also assuming addCategory is also broken.

private func addQuantity(
reporter: HealthKitReporter,
arguments: [String: Any],
result: @escaping FlutterResult
) {
guard
let quantity = arguments["quantities"] as? [[String: Any]],
let workout = arguments["workout"] as? [String: Any]
else {
throwParsingArgumentsError(result: result, arguments: arguments)
return
}
let device = arguments["device"] as? [String: Any]
do {
reporter.writer.addQuantitiy(try quantity.map {
try Quantity.make(from: $0)
},
from: device != nil
? try Device.make(from: device!)
: nil,
to: try Workout.make(from: workout)) { (success, error) in
guard error == nil else {
result(
FlutterError(
code: "AddQuantity",
message: "Error in addQuantity",
details: error.debugDescription
)
)
return
}
result(success)
}
} catch {
throwPlatformError(result: result, error: error)
}
}

Fix

  private func addQuantity(
    reporter: HealthKitReporter,
    arguments: [String: Any],
    result: @escaping FlutterResult
  ) {
    guard
      let quantity = arguments["quantities"] as? [[String: Any]],
      let workout = arguments["workout"] as? [String: Any]
    else {
      throwParsingArgumentsError(result: result, arguments: arguments)
      return
    }

    let device = arguments["device"] as? [String: Any]
    do {
      let w = try Workout.make(from: workout)
      reporter.writer.addQuantitiy(
        try quantity.map {
          let q = try Quantity.make(from: $0)
          return q.copyWith(
            startTimestamp: q.startTimestamp.secondsSince1970,
            endTimestamp: q.endTimestamp.secondsSince1970
          )
        },
        from: device != nil
          ? try Device.make(from: device!)
          : nil,
        to: w.copyWith(
          startTimestamp: w.startTimestamp.secondsSince1970,
          endTimestamp: w.endTimestamp.secondsSince1970,
          workoutEvents: w.workoutEvents.map { event in
            event.copyWith(
              startTimestamp: event.startTimestamp.secondsSince1970,
              endTimestamp: event.endTimestamp.secondsSince1970
            )
          }
        )
      ) { (success, error) in
        guard error == nil else {
          result(
            FlutterError(
              code: "AddQuantity",
              message: "Error in addQuantity",
              details: error.debugDescription
            )
          )
          return
        }
        result(success)
      }
    } catch {
      throwPlatformError(result: result, error: error)
    }
  }

from health_kit_reporter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.