cph-cachet / research.package

A Flutter package implementing support for surveys like ResearchStack and ResearchKit
MIT License
51 stars 44 forks source link

RPTaskResult: startTime is inaccurate and endTime is not available #136

Open mario-bermonti opened 1 week ago

mario-bermonti commented 1 week ago

The problem occurs in the _translateTaskResult method. This method is called by the createAndSendResult when the task ends. It translates the task RPTaskResult to the locale used during the task.

_translateTaskResult creates a new RPTaskResult to store the translated data. In the process, it introduces 2 problems:

  1. RPTaskResult's startTime changes to the time the new RPTaskResult is created, and it is no longer the time the data was collected (startTime of the original RPTaskResult). This makes it inaccurate.
  2. endTime is never set in the new RPTaskResult, so it becomes null.

I replicated this bug in the example application provided in the package.

I did a quick check and was able to fix it by just setting the startTime and endTime in the new RPTaskResult. I will work on it more carefully and submit a pull request soon.