单击提交调查按钮后如何添加线性进度指标



我希望在用户单击提交调查后显示一个线性进度指示器和一个循环进度指示器。

此外,有没有更好的方法可以在不使用调查工具包的情况下编写调查代码?

以下是所使用任务的完整代码:

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:survey_kit/survey_kit.dart';

void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Container(
color: Colors.white,
child: Align(
alignment: Alignment.center,
child: FutureBuilder<Task>(
future: getSampleTask(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
snapshot.hasData &&
snapshot.data != null) {
final task = snapshot.data!;
return SurveyKit(
onResult: (SurveyResult result) {
print(result.finishReason);
},
task: task,
themeData: Theme.of(context).copyWith(
colorScheme: ColorScheme.fromSwatch(
primarySwatch: Colors.cyan,
).copyWith(
onPrimary: Colors.white,
),
primaryColor: Colors.cyan,
backgroundColor: Colors.white,
appBarTheme: const AppBarTheme(
color: Colors.white,
iconTheme: IconThemeData(
color: Colors.cyan,
),
textTheme: TextTheme(
button: TextStyle(
color: Colors.cyan,
),
),
),
iconTheme: const IconThemeData(
color: Colors.cyan,
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: ButtonStyle(
minimumSize: MaterialStateProperty.all(
Size(150.0, 60.0),
),
side: MaterialStateProperty.resolveWith(
(Set<MaterialState> state) {
if (state.contains(MaterialState.disabled)) {
return BorderSide(
color: Colors.grey,
);
}
return BorderSide(
color: Colors.cyan,
);
},
),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
),
textStyle: MaterialStateProperty.resolveWith(
(Set<MaterialState> state) {
if (state.contains(MaterialState.disabled)) {
return Theme.of(context)
.textTheme
.button
?.copyWith(
color: Colors.grey,
);
}
return Theme.of(context)
.textTheme
.button
?.copyWith(
color: Colors.cyan,
);
},
),
),
),
textButtonTheme: TextButtonThemeData(
style: ButtonStyle(
textStyle: MaterialStateProperty.all(
Theme.of(context).textTheme.button?.copyWith(
color: Colors.cyan,
),
),
),
),
),
);
}
return CircularProgressIndicator();
},
),
),
),
),
);
}
Future<Task> getSampleTask() {
var task = NavigableTask(
id: TaskIdentifier(),
steps: [
InstructionStep(
title: 'Dear Customer,nCongratulations!',
text:
'Simply take this short survey about your experience with us.nnClick LET'S GO!         to   begin.',
buttonText: 'Let's go!',
),
QuestionStep(
title: 'Question 1 out of 7:',
text: 'Which type of shipping do you use most often?',
answerFormat: SingleChoiceAnswerFormat(
textChoices: [
TextChoice(text: 'Letter', value: 'Letter'),
TextChoice(text: 'Parcel', value: 'Parcel'),
TextChoice(text: 'Oversize shipping', value: 'Oversize shipping'),
TextChoice(text: 'None of the above', value: 'None of the above'),
],
),
),
QuestionStep(
title: 'Question 2 out of 7:',
text:
'Do you agree for the Pricing for the type of shipment you prefer?',
answerFormat: SingleChoiceAnswerFormat(
textChoices: [
TextChoice(text: 'Yes', value: 'Yes'),
TextChoice(text: 'No', value: 'No'),
TextChoice(text: 'Not sure', value: 'Not sure'),
],
),
),
QuestionStep(
title: 'Question 3 out of 7:',
text: 'How would you rate our package tracking system?',
answerFormat: SingleChoiceAnswerFormat(
textChoices: [
TextChoice(text: 'Excellent', value: 'Excellent'),
TextChoice(text: 'Good', value: 'Good'),
TextChoice(text: 'Not good', value: 'Not good'),
TextChoice(text: 'Not sure', value: 'Not sure'),
],
),
),
QuestionStep(
title: 'Question 4 out of 7:',
text: 'Have you ever used our complaints department?',
answerFormat: SingleChoiceAnswerFormat(
textChoices: [
TextChoice(text: 'Yes', value: 'Yes'),
TextChoice(text: 'No', value: 'No'),
],
),
),
QuestionStep(
title: 'Question 5 out of 7:',
text: 'Would you consider recommending our shipping/courier service?',
answerFormat: SingleChoiceAnswerFormat(
textChoices: [
TextChoice(text: 'Yes', value: 'Yes'),
TextChoice(text: 'No', value: 'No'),
],
),
),
QuestionStep(
title: 'Question 6 out of 7:',
text: 'Have you ever participated in our survey rewards program?',
answerFormat: SingleChoiceAnswerFormat(
textChoices: [
TextChoice(text: 'Yes', value: 'Yes'),
TextChoice(text: 'No', value: 'No'),
],
),
),
QuestionStep(
title: 'Question 7 out of 7:',
text:
'Would you like to receive notifications about sales and discounts?',
answerFormat: SingleChoiceAnswerFormat(
textChoices: [
TextChoice(text: 'Yes', value: 'Yes'),
TextChoice(text: 'No', value: 'No'),
],
),
),
//This is where the Submit Survey button is
CompletionStep(
stepIdentifier: StepIdentifier(id: '321'),
title: 'Done',
text:
'thanks for taking the survey!',
buttonText: 'Submit survey',
//I want it to take the user to a new page where aminated percent indicators are used
),
],
);
task.addNavigationRule(
forTriggerStepIdentifier: task.steps[7].stepIdentifier,
navigationRule: ConditionalNavigationRule(
resultToStepIdentifierMapper: (input) {
switch (input) {
case "Yes":
return task.steps[0].stepIdentifier;
case "No":
return task.steps[7].stepIdentifier;
default:
return null;
}
},
),
);
return Future.value(task);
}
Future<Task> getJsonTask() async {
final taskJson = await rootBundle.loadString('assets/example_json.json');
final taskMap = json.decode(taskJson);
return Task.fromJson(taskMap);
}
}

线性进度指示器已添加到survey_kit的新版本中。默认情况下,提交调查后会显示循环进度指示器。

最新更新