goxiaoy / flutter_survey_js

Flutter client library for parsing and display surveyjs.io survey
https://goxiaoy.github.io/flutter_survey_js/
MIT License
17 stars 18 forks source link

With reference #79 issue, I am getting type error #91

Closed Vpdwivedi closed 1 year ago

Vpdwivedi commented 1 year ago

Describe the bug Getting the error '_Map<dynamic, dynamic>' is not a subtype of type 'Map<String, Object?>?' however I am storing the survey response data to HiveBox and then sending the same response data to answer. If I add a survey and edit the same response works fine but Error coms when I restart the application and then going to the edit survey screen.

To Reproduce SurveyJs json

{
 "title": "Survey Form for Commune",
 "description": "Survey for commune level users",
 "logoFit": "cover",
 "logoPosition": "right",
 "pages": [
  {
   "name": "Page1",
   "elements": [
    {
     "type": "matrixdynamic",
     "name": "question1",
     "title": "Question 1",
     "columns": [
      {
       "name": "Column 1"
      },
      {
       "name": "Column 2"
      },
      {
       "name": "Column 3"
      }
     ],
     "choices": [
      1,
      2,
      3,
      4,
      5
     ]
    }
   ],
   "title": "I. COUVERTURE DES RISQUES SOCIAUX",
   "description": "Tableau001 : Couverture dela population par les mutuelles sociales toutes prestations (Une liste demutuelle sera fournie)"
  },
  {
   "name": "page2",
   "elements": [
    {
     "type": "matrixdynamic",
     "name": "question2",
     "title": "Question1",
     "columns": [
      {
       "name": "Column 1"
      },
      {
       "name": "Column 2"
      },
      {
       "name": "Column 3"
      }
     ],
     "choices": [
      1,
      2,
      3,
      4,
      5
     ]
    }
   ],
   "title": "1.2. Assurance Maladie Obligatoire (AMO)",
   "description": "Tableau 002 : Couverture de la population par l’AMO (interopérabilité entre le SISo et la base de la CANAM)"
  }
 ]
}

SurveyJs answer

{question1: [{Column 1: 2, Column 2: 2, Column 3: 2}], question2: []}

Expected behavior

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

goxiaoy commented 1 year ago

Not familiar with HiveBox, but I believe that you can try to store as string into HiveBox and then deserialize it as Map<String, Object?>

s.SurveyWidget(
      survey: survey!,
      onChange: (v) {
         final String s = json.encode(v);
         // put s into hivebox
      }

after your application restart

FutureBuilder(
  future:  //get s from hivebox
  builder :(){
      s.SurveyWidget(
        survey: survey!,
        answer: json.decode(snapshot.data)
   }
)
Vpdwivedi commented 1 year ago

This worked for me. You are awesome!. Thanks you so much.