surveykit
create beautiful surveys with flutter (inspired by ios researchkit surveys)
do you want to display a questionnaire to get the opinion of your users? a survey for a medical trial? a series of instructions in a manual-like style?
surveykit is an flutter library that allows you to create exactly that.
thematically it is built to provide a feeling of a professional research survey. the library aims to be visually clean, lean and easily configurable. we aim to keep the functionality close to ios researchkit surveys. we also created a surveykit version for native android developers, check it out here
this is an early version and work in progress. do not hesitate to give feedback, ideas or improvements via an issue.
examples
flow
screenshots
what surveykit does for you
- simplifies the creation of surveys
- provides rich animations and transitions out of the box (custom animations planned)
- build with a consistent, lean, simple style, to fit research purposes
- survey navigation can be linear or based on a decision tree (directed graph)
- gathers results and provides them in a convinient manner to the developer for further use
- gives you complete freedom on creating your own questions
- allows you to customize the style
- provides an api and structure that is very similar to ios researchkit surveys
what surveykit does not (yet) do for you
as stated before, this is an early version and a work in progress. we aim to extend this library until it matches the functionality of the ios researchkit surveys.
�� setup
to use this plugin, add flutter_surveykit as a dependency in your pubspec.yaml file.
1. add the dependecy
pubspec.yaml
dependencies:
surveykit: ^0.1
2. install it
flutter pub get
3. import it
import 'package:survey_kit/survey_kit.dart';
�� usage
example
a working example project can be found here
create survey steps
to create a step, create an instance of one of these 3 classes:
instructionstep
instructionstep(
title: 'your journey starts here',
text: 'have fun with a quick survey',
buttontext: 'start survey',
);
the title
is the general title of the survey you want to conduct.
the text
is, in this case, the introduction text which should give an introduction, about what the survey is about.
the buttontext
specifies the text of the button, which will start the survey.
all of these properties have to be resource ids.
completionstep
completionstep(
title: 'you are done',
text: 'you have finished !!!',
buttontext: 'submit survey',
);
the title
is the general title of the survey you want to conduct, same as for the instructionstep
.
the text
is here should be something motivational: that the survey has been completed successfully.
the buttontext
specifies the text of the button, which will end the survey.
all of these properties have to be resource ids.
questionstep
questionstep(
title: 'sample title',
text: 'sample text',
answerformat: textanswerformat(
maxlines: 5,
),
);
the title
same as for the instructionstep
and completionstep
.
the text
the actual question you want to ask. depending on the answer type of this, you should set the next property.
the answerformat
specifies the type of question (the type of answer to the question) you want to ask. currently there these types supported:
textanswerformat
integeranswerformat
scaleanswerformat
singlechoiceanswerformat
multiplechoiceanswerformat
booleananswerformat
all that’s left is to collect your steps in a list or add them inline in the widget.
var steps = [step1, step2, step3, ...]
create a task
next you need a task. each survey has exactly one task. a task
is used to define how the user should navigate through your steps
.
orderedtask
var task = orderedtask(steps: steps)
the orderedtask
just presents the questions in order, as they are given.
navigableorderedtask
var task = navigableorderedtask(steps: steps)
the navigableorderedtask
allows you to specify navigation rules.
there are two types of navigation rules:
with the directstepnavigationrule
you say that after this step, another specified step should follow.
task.addnavigationrule(
fortriggerstepidentifier: steps[4].id,
navigationrule: directstepnavigationrule(
destinationstepstepidentifier: steps[6].id
),
);
with the multipledirectionstepnavigationrule
you can specify the next step, depending on the answer of the step.
task.addnavigationrule(
fortriggerstepidentifier: task.steps[6].id,
navigationrule: conditionalnavigationrule(
resulttostepidentifiermapper: (input) {
switch (input) {
case "yes":
return task.steps[0].id;
case "no":
return task.steps[7].id;
default:
return null;
}
},
),
);
evaluate the results
when the survey is finished, you get a callback. no matter of the finishreason
, you always get all results gathered until now.
the surveyresult
contains a list of stepresult
s and the finishreason
. the stepresult
contains a list of questionresult
s.
surveykit(
onresult: (surveyresult result) {
//read finish reason from result (result.finishreason)
//and evaluate the results
},
)
style
there are already many adaptive elements for android and ios implemented. in the future development other parts will be adapted too.
the styling can be adjusted by the build in flutter theme.
start the survey
all that’s left is to insert the survey in the widget tree and enjoy.����
scaffold(
body: surveykit(
onresult: (surveyresult result) {
//evaluate results
},
task: orderedtask(),
theme: customthemedata(),
)
);
�� custom steps
at some point, you might wanna define your own custom question steps.
that could, for example, be a question which prompts the user to pick color values or even sound samples.
these are not implemented yet but you can easily create them yourself:
you’ll need a customresult
and a customstep
. the result class tells surveykit which data you want to save.
class customresult extends questionresult<string> {
final string customdata;
final string valueidentifier;
final identifier identifier;
final datetime startdate;
final datetime enddate;
final string value; //custom value
}
next you’ll need a customstep class. it is recommended to use the stepview
widget as your foundation. it gives you the appbar and the next button.
class customstep extends step {
final string title;
final string text;
customstep({
@required stepidentifier id,
bool isoptional = false,
string buttontext = 'next',
this.title,
this.text,
}) : super(isoptional, id, buttontext);
@override
widget createview({@required questionresult questionresult}) {
return stepview(
step: widget.questionstep,
result: () => customresult(
id: id,
startdate: datetime.now(),
enddate: datetime.now(),
valueidentifier: 'custom'//identification for navigabletask,
result: 'custom_result',
),
title: text('title'),
child: container(), //add your view here
);
}
}
if you want to create a complete custom view or just override the navigation behavior you should use the surveycontroller with its three methods:
- onnextstep()
- onstepback()
- onclosesurvey()
Comments are closed.