Skip to content

Commit

Permalink
support swipe
Browse files Browse the repository at this point in the history
  • Loading branch information
eldrig0 committed Nov 3, 2023
1 parent cd38246 commit ea363a6
Showing 1 changed file with 44 additions and 34 deletions.
78 changes: 44 additions & 34 deletions lib/src/survey_kit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,41 +170,51 @@ class _SurveyPageState extends State<SurveyPage> {

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: widget.backgroundColor,
appBar: widget.appBar ?? const SurveyAppBar(),
body: Navigator(
key: widget.navigatorKey,
observers: [routeObserver],
onGenerateRoute: (settings) {
final arg = settings.arguments;
var step = widget.step;
SurveyState? surveyState;
if (arg is SurveyState) {
surveyState = settings.arguments! as SurveyState;

step = surveyState.currentStep!;
}
return CupertinoPageRoute<Widget>(
settings: settings,
builder: (_) {
return _SurveyView(
key: ValueKey<String>(
step.id,
),
id: step.id,
decoration: widget.decoration,
createView: () => AnswerView(
answer: step.answerFormat,
step: step,
stepResult: surveyState?.questionResults.firstWhereOrNull(
(element) => element.id == step.id,
final currentStepIndex =
Provider.of<SurveyStateProvider>(context, listen: false)
.state
?.currentStepIndex;

return WillPopScope(
onWillPop: currentStepIndex == null && currentStepIndex == 0
? null
: () async => false,
child: Scaffold(
backgroundColor: widget.backgroundColor,
appBar: widget.appBar ?? const SurveyAppBar(),
body: Navigator(
key: widget.navigatorKey,
observers: [routeObserver],
onGenerateRoute: (settings) {
final arg = settings.arguments;
var step = widget.step;
SurveyState? surveyState;
if (arg is SurveyState) {
surveyState = settings.arguments! as SurveyState;

step = surveyState.currentStep!;
}
return CupertinoPageRoute<Widget>(
settings: settings,
builder: (_) {
return _SurveyView(
key: ValueKey<String>(
step.id,
),
),
);
},
);
},
id: step.id,
decoration: widget.decoration,
createView: () => AnswerView(
answer: step.answerFormat,
step: step,
stepResult: surveyState?.questionResults.firstWhereOrNull(
(element) => element.id == step.id,
),
),
);
},
);
},
),
),
);
}
Expand Down

0 comments on commit ea363a6

Please sign in to comment.