Skip to content

Commit 0241ff9

Browse files
committed
refactor: streamline SurveyKit state management by initializing SurveyStateProvider in initState
1 parent 2684c7f commit 0241ff9

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

lib/src/survey_kit.dart

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,27 @@ class SurveyKit extends StatefulWidget {
7272
class _SurveyKitState extends State<SurveyKit> {
7373
late TaskNavigator _taskNavigator;
7474
late final GlobalKey<NavigatorState> _navigatorKey;
75+
late final SurveyStateProvider _surveyStateProvider;
7576

7677
@override
7778
void initState() {
7879
super.initState();
7980
_taskNavigator = _createTaskNavigator();
8081
_navigatorKey = GlobalKey<NavigatorState>();
82+
_surveyStateProvider = SurveyStateProvider(
83+
taskNavigator: _taskNavigator,
84+
onResult: widget.onResult,
85+
stepShell: widget.stepShell,
86+
navigatorKey: _navigatorKey,
87+
child: SurveyPage(
88+
backgroundColor: widget.backgroundColor,
89+
length: widget.task.steps.length,
90+
onResult: widget.onResult,
91+
appBar: widget.appBar,
92+
navigatorKey: _navigatorKey,
93+
decoration: widget.decoration,
94+
),
95+
);
8196
}
8297

8398
TaskNavigator _createTaskNavigator() {
@@ -106,20 +121,7 @@ class _SurveyKitState extends State<SurveyKit> {
106121
surveyController: widget.surveyController ?? SurveyController(),
107122
localizations: widget.localizations,
108123
padding: const EdgeInsets.all(14),
109-
child: SurveyStateProvider(
110-
taskNavigator: _taskNavigator,
111-
onResult: widget.onResult,
112-
stepShell: widget.stepShell,
113-
navigatorKey: _navigatorKey,
114-
child: SurveyPage(
115-
backgroundColor: widget.backgroundColor,
116-
length: widget.task.steps.length,
117-
onResult: widget.onResult,
118-
appBar: widget.appBar,
119-
navigatorKey: _navigatorKey,
120-
decoration: widget.decoration,
121-
),
122-
),
124+
child: _surveyStateProvider,
123125
);
124126
}
125127
}

0 commit comments

Comments
 (0)