survey_kit icon indicating copy to clipboard operation
survey_kit copied to clipboard

1.0.0 Example Code needs a few tweaks and fails Task.fromJson

Open kiwicmc opened this issue 9 months ago • 1 comments

I like this component, but need to supply it with Survey questions externally.

To get to work with the hardcoded survey I needed to do the following:

Had to download app_bar_example.dart from git Changed to https for video file: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4', Added assets directory and downloaded example_json.json and fancy_checkmark.json from repo Add assets to pubspec.yaml Works with hard coded getSampleTask When I try to load the JSON example for getJsonTask throws Exception

Image

flutter doctor -v
[✓] Flutter (Channel stable, 3.29.2, on macOS 13.6 22G120 darwin-arm64, locale en-NZ) [444ms]
    • Flutter version 3.29.2 on channel stable at /Users/chris/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c236373904 (12 days ago), 2025-03-13 16:17:06 -0400
    • Engine revision 18b71d647a
    • Dart version 3.7.2
    • DevTools version 2.42.3

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [484ms]
    • Android SDK at /Users/chris/Library/Android/sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/macos-android-setup for more details.

[!] Xcode - develop for iOS and macOS (Xcode 15.2) [1,053ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    ! CocoaPods 1.14.2 out of date (1.16.2 is recommended).
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods

[✓] Chrome - develop for the web [153ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed) [153ms]
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/to/macos-android-setup for detailed instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.7) [153ms]
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 79.0.1
    • Dart plugin version 232.10313

[✓] IntelliJ IDEA Ultimate Edition (version 2024.3.5) [64ms]
    • IntelliJ at /Applications/IntelliJ IDEA 2024.app
    • Flutter plugin version 83.0.4
    • Dart plugin version 243.26053.17

[✓] Connected device (5 available) [6.8s]
    • SM A105G (mobile)               • RF8M61TGCRL                          • android-arm    • Android 11 (API 30)
    • iPhone 15 Pro (mobile)          • 0044387B-1B6E-4F5D-979B-0637D6BCE451 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 13.6 22G120 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 13.6 22G120 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 134.0.6998.166
! Error: Browsing on the local area network for iPhone XS. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
  The device must be opted into Developer Mode to connect wirelessly. (code -27)
! Error: Browsing on the local area network for iPhone 13 Mini. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
  The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources [484ms] • All expected network resources are available.

kiwicmc avatar Mar 26 '25 03:03 kiwicmc

This is an amended example_json.json that works without crashing (always have a text type, multi instead of multiple.

{
  "id": "123",
  "type": "navigable",
  "rules": [{
      "type": "conditional",
      "triggerStepIdentifier": {
        "id": "7"
      },
      "values": {
        "Yes": "2",
        "No": "8"
      }
    },
    {
      "type": "direct",
      "triggerStepIdentifier": {
        "id": "1"
      },
      "destinationStepIdentifier": "3"
    },
    {
      "type": "conditional",
      "triggerStepIdentifier": {
        "id": "6"
      },
      "values": {
        "Penicillin": "7",
        "Penicillin,Latex": "7",
        "Penicillin,Latex,Pet": "11",
        "Penicillin,Latex,Pet,Pollen": "11",
        "Penicillin,Pet": "11",
        "Penicillin,Pet,Pollen": "11",
        "Penicillin,Pollen": "7",
        "Latex": "7",
        "Latex,Pet": "11",
        "Latex,Pet,Pollen": "11",
        "Latex,Pollen": "7",
        "Pet": "11",
        "Pet,Pollen": "11",
        "Pollen": "7"
      }
    },
    {
      "type": "direct",
      "triggerStepIdentifier": {
        "id": "11"
      },
      "destinationStepIdentifier": "7"
    }
  ],
  "steps": [
    {
      "id": "1",
      "content": [
        {
          "type": "text",
          "title": "Welcome to the\nQuickBird Studios\nHealth Survey",
          "text": "Get ready for a bunch of super random questions!"
        }
      ],
      "buttonText": "Let's go!"
    },
    {
      "id": "2",
      "content": [
        {
          "type": "text",
          "title": "Age",
          "text": "How old are you?"
        }
      ],
      "answerFormat": {
        "type": "integer",
        "defaultValue": 25,
        "hint": "Please enter your age"
      }
    },
    {
      "id": "3",
      "content": [
        {
          "type": "text",
          "title": "Medication?",
          "text": "Are you using any medication"
        }
      ],
      "answerFormat": {
        "type": "bool",
        "positiveAnswer": "Yes",
        "negativeAnswer": "No",
        "result": "positive"
      }
    },
    {
      "id": "4",
      "content": [
        {
          "type": "text",
          "title": "Tell us about you",
          "text": "Tell us about yourself and why you want to improve your health."
        }
      ],
      "answerFormat": {
        "type": "text",
        "maxLines": 5,
        "validationRegEx": "^(?!\\s*\\$).+"
      }
    },
    {
      "id": "5",
      "content": [
        {
          "type": "text",
          "title": "Body Type",
          "text": "Select your body type"
        }
      ],
      "answerFormat": {
        "type": "scale",
        "step": 1,
        "minimumValue": 1,
        "maximumValue": 5,
        "defaultValue": 3,
        "minimumValueDescription": "1",
        "maximumValueDescription": "5"
      }
    },
    {
      "id": "6",
      "content": [
        {
          "type": "text",
          "text": "Known allergies"
        }
      ],
      "answerFormat": {
        "type": "multi",
        "textChoices": [{
          "text": "Penicillin",
          "value": "Penicillin"
        },
          {
            "text": "Latex",
            "value": "Latex"
          },
          {
            "text": "Pet",
            "value": "Pet"
          },
          {
            "text": "Pollen",
            "value": "Pollen"
          }
        ]
      }
    },
    {
      "id": "7",
      "content": [
        {
          "type": "text",
          "title": "Done?",
          "text": "We are done, do you mind to tell us more about yourself?"
        }
      ],
      "answerFormat": {
        "type": "single",
        "textChoices": [{
          "text": "Yes",
          "value": "Yes"
        },
          {
            "text": "No",
            "value": "No"
          }
        ]
      }
    },
    {
      "id": "8",
      "content": [
        {
          "type": "text",
          "text": "When did you wake up?"
        }
      ],
      "answerFormat": {
        "type": "time",
        "defaultValue": {
          "hour": 12,
          "minute": 0
        }
      }
    },
    {
      "id": "9",
      "content": [
        {
          "type": "text",
          "text": "When was your last holiday?"
        }
      ],
      "answerFormat": {
        "type": "date",
        "minDate": "2015-06-25T04:08:16Z",
        "maxDate": "2025-06-25T04:08:16Z",
        "defaultDate": "2021-06-25T04:08:16Z"
      }
    },
    {
      "id": "10",
      "content": [
        {
          "type": "text",
          "text": "Thanks for taking the survey, we will contact you soon!",
          "title": "Done!",
          "buttonText": "Restart"
        }
      ]
    },
    {
      "id": "11",
      "content": [
        {
          "type": "text",
          "title": "Pets",
          "text": "What type of pet(s) do you have?"
        }
      ],
      "answerFormat": {
        "type": "multi",
        "textChoices": [{
          "text": "Dog",
          "value": "Dog"
        },
          {
            "text": "Cat",
            "value": "Cat"
          },
          {
            "text": "Fish",
            "value": "Fish"
          },
          {
            "text": "Small Animal",
            "value": "Small Animal"
          }
        ]
      }
    }
  ]
}

ChrisMICDUP avatar Mar 30 '25 21:03 ChrisMICDUP