blockbasti / just_another_workout_timer

A simple timer for your workouts, built with Flutter!
MIT License
130 stars 23 forks source link

Import a backup isn't working #95

Closed MaxSchlueter closed 2 years ago

MaxSchlueter commented 2 years ago

Describe the bug Importing a backup that I've previously exported to a file isn't working, the workout doesn't show up in the list.

To Reproduce Steps to reproduce the behavior:

  1. Go to Settings
  2. Click on "Import a backup"
  3. Selected a previously exported workout
  4. The previously exported workout doesn't show up in the list of workouts

Expected behavior Would expect the workout to show up in the list.

Smartphone (please complete the following information):

blockbasti commented 2 years ago

Did you create the backup by exporting a workout or did you just copy the files from the data folder?

MaxSchlueter commented 2 years ago

I created the backup by exporting a workout.

blockbasti commented 2 years ago

I can't reproduce this on my device. Can you provide me with the backup file, so i can try it myself?

MaxSchlueter commented 2 years ago

Sure, this is the content of the exported workout (Test.json):

{
  "workouts": [
    {
      "title": "Test",
      "sets": [
        {
          "repetitions": 1,
          "id": "265d3e45-1f21-49ea-b9d4-7336f968cb3a",
          "exercises": [
            {
              "name": "Exercise",
              "id": "73492695-08a3-487f-b52a-cb9cc5051a63",
              "duration": 30
            }
          ]
        }
      ],
      "version": 2,
      "position": 10
    }
  ]
}
blockbasti commented 2 years ago

I imported the file successfully on my real device and dev emulator.

MaxSchlueter commented 2 years ago

I could import the file successfully as well on my old smartphone which is running Android 7. It's still not working on my current one, a Pixel 2 running Android 11 (Lineage OS).

Franziskus1988 commented 2 years ago

I'm using a Xiaomi Mi 8 with the latest Lineage OS 18.1 and it is not working, too.

Franziskus1988 commented 2 years ago

@blockbasti

So, I debugged the app and the importing and I think I found the problem: In storage_helper.dart:48 you are importing the data with the

var backup = await File(filePath).readAsString();

In my case this throws an exception due to an malformed utf8 encoding. I'm not very experienced in Android/Flutter development so I "DuckDuckGo-ed" and found a similar problem here: https://github.com/dart-lang/pana/pull/759

After changing the above code to

    var bytes = await File(filePath).readAsBytes();
    var backup = utf8.decode(bytes, allowMalformed: true);

it works perfectly fine! Of course you could follow the discussion from the mentioned link to write this a little bit nicer and don't allowMalformed per default ;)

Hope this helped.

blockbasti commented 2 years ago

@Franziskus1988 thank you for finding this. Could you please create a pull request with these changes?