Comments (4)
Hi, first of all thanks for your feedback.
I tried a similar example by wrapping the "getTask" method in the example with a future and used that in the FutureBuilder. It works completly fine for me.
Maybe your build method with the FutureBuilder is called several times, so your backend is called more than once, which could result in a rebuild of the survey.
Hope that helps you.
from survey_kit.
from survey_kit.
So i tried it again with your code sample. I modified it a little bit but it should be quite similar to your example:
import 'package:flutter/material.dart';
import 'package:survey_kit/survey_kit.dart' as Survey;
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SurveyForm(),
),
);
}
}
class SurveyForm extends StatefulWidget {
@override
_SurveyFormState createState() => _SurveyFormState();
}
class _SurveyFormState extends State<SurveyForm> {
Future<List<Survey.Step>> getQuestionSteps() async {
List<Survey.Step> questionSteps = List.filled(
1,
Survey.InstructionStep(
title: 'Your journey starts here',
text:
'In order to identify actions and possibilities for the coaching process, the coachee is asked to answer the following questions. This is an open exploration, the coach presents himself totally available and at the service of the coachee, to find out their current energy for change, in intensity and direction. ',
buttonText: 'START QUESTIONNAIRE',
),
growable: true);
final _questions = [
Survey.QuestionStep(
title: 'How old are you?',
answerFormat: Survey.IntegerAnswerFormat(
defaultValue: 25,
hint: 'Please enter your age',
),
),
Survey.QuestionStep(
title: 'Medication?',
text: 'Are you using any medication',
answerFormat: Survey.BooleanAnswerFormat(
positiveAnswer: 'Yes',
negativeAnswer: 'No',
result: Survey.BooleanResult.POSITIVE,
),
),
Survey.QuestionStep(
title: 'Tell us about you',
text: 'Tell us about yourself and why you want to improve your health.',
answerFormat: Survey.TextAnswerFormat(
maxLines: 5,
),
),
Survey.QuestionStep(
title: 'Select your body type',
answerFormat: Survey.ScaleAnswerFormat(
step: 1,
minimumValue: 1,
maximumValue: 5,
defaultValue: 3,
minimumValueDescription: '1',
maximumValueDescription: '5',
),
),
];
questionSteps.addAll(_questions);
questionSteps.add(Survey.CompletionStep(
id: Survey.StepIdentifier(id: '1123123'),
title: 'You are done',
text: 'You have finished !!!',
buttonText: 'Submit survey',
));
return questionSteps;
}
@override
Widget build(BuildContext context) {
final screenSize = MediaQuery.of(context).size;
return MaterialApp(
home: Scaffold(
body: FutureBuilder<List<Survey.Step>>(
future: getQuestionSteps(),
builder: (ctx, snapshot) {
// Checking if future is resolved or not
if (snapshot.connectionState == ConnectionState.done) {
// If we got an error
if (snapshot.hasError) {
return Center(
child: Text(
'${snapshot.error} occured',
style: TextStyle(fontSize: 18),
),
);
// if we got our data
} else if (snapshot.hasData) {
// Extracting data from snapshot object
final questionSteps = snapshot.data!;
return Survey.SurveyKit(
onResult: (Survey.SurveyResult result) {
print(result.finishReason);
},
task: getSampleTask(questionSteps));
}
}
// Displaying LoadingSpinner to indicate waiting state
return Center(
child: CircularProgressIndicator(),
);
},
)),
);
}
Survey.Task getSampleTask(List<Survey.Step> _questionSteps) {
var task = Survey.NavigableTask(
id: Survey.TaskIdentifier(),
steps: _questionSteps,
);
task.addNavigationRule(
forTriggerStepIdentifier: task.steps[2].id,
navigationRule: Survey.ConditionalNavigationRule(
resultToStepIdentifierMapper: (input) {
switch (input) {
case "Yes":
return task.steps[0].id;
case "No":
return task.steps[3].id;
default:
return null;
}
},
),
);
return task;
}
}
It still does work for me. One thing i noticed is that you have some navigation rules in place. If on the third step the user types/clicks "Yes" (The valueIdentifier) the user goes back to the first Step (InstructionsStep). Maybe that is the reason?
task.addNavigationRule(
forTriggerStepIdentifier: task.steps[2].id,
navigationRule: Survey.ConditionalNavigationRule(
resultToStepIdentifierMapper: (input) {
switch (input) {
case "Yes":
return task.steps[0].id;
case "No":
return task.steps[3].id;
default:
return null;
}
},
),
);
from survey_kit.
from survey_kit.
Related Issues (20)
- How to use Padding to show questions?
- Get ordered type from json file.
- I wish there was a function to reset the result value.
- Add support for navigating back when initial step is present
- How to have EDIT functionality in the form?
- added this dep and ran the project this error pops up ? HOT 1
- Years of the calendar are not showing with flutter version 3.10 (stable) HOT 1
- Example not working HOT 1
- Navigate to next question without using next button HOT 2
- BooleanAnswerView isOptional not functioning as expected. HOT 1
- onNextStep not working HOT 1
- Question: Any way to pick up intermediary results? HOT 1
- Is it possible to save the results as we go to the next question so that problems wont arise if its a very lengthy survey? HOT 1
- how to have more than one question per question step? HOT 1
- example app does not build/run HOT 5
- Custom Step / Custom Slider HOT 5
- Controller's length property (19) does not match the number of children (37) present in TabBarView's children property. HOT 1
- Results not publishing on stepBack and stepForward HOT 5
- Instance of text choice
- Localization to next text doesn't work HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from survey_kit.