Skip to content

Commit

Permalink
fix: fix background decoration of survey page
Browse files Browse the repository at this point in the history
  • Loading branch information
Numoy committed Sep 19, 2023
1 parent bf53b09 commit 7f38c56
Showing 1 changed file with 38 additions and 33 deletions.
71 changes: 38 additions & 33 deletions lib/src/survey_kit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class SurveyKit extends StatefulWidget {
/// Widget which is shown while the survey is loading (isLoading = true)
final Widget? loadingState;

final bool keepLastStateAlive;

const SurveyKit({
super.key,
required this.task,
Expand All @@ -51,6 +53,7 @@ class SurveyKit extends StatefulWidget {
this.stepShell,
this.decoration,
this.loadingState,
this.keepLastStateAlive = false,
});

@override
Expand Down Expand Up @@ -109,6 +112,7 @@ class _SurveyKitState extends State<SurveyKit> {
navigatorKey: _navigatorKey,
decoration: widget.decoration,
loadingState: widget.loadingState,
keepLastStateAlive: widget.keepLastStateAlive,
);
},
),
Expand All @@ -121,8 +125,9 @@ class SurveyPage extends StatefulWidget {
final Function(SurveyResult) onResult;
final PreferredSizeWidget? appBar;
final GlobalKey<NavigatorState> navigatorKey;
final Decoration? decoration;
final BoxDecoration? decoration;
final Widget? loadingState;
final bool keepLastStateAlive;

const SurveyPage({
super.key,
Expand All @@ -132,6 +137,7 @@ class SurveyPage extends StatefulWidget {
this.appBar,
this.decoration,
this.loadingState,
this.keepLastStateAlive = false,
});

@override
Expand All @@ -152,63 +158,62 @@ class _SurveyPageState extends State<SurveyPage>

@override
Widget build(BuildContext context) {
Widget scaffold(Widget child) => Scaffold(
appBar: widget.appBar ?? const SurveyAppBar(),
body: Container(
decoration: widget.decoration,
child: child,
),
);

return Navigator(
key: widget.navigatorKey,
onGenerateRoute: (settings) => CupertinoPageRoute<Widget>(
builder: (_) {
if (settings.arguments is! SurveyState) {
return scaffold(
widget.loadingState ??
return Scaffold(
appBar: widget.appBar ?? const SurveyAppBar(),
body: Navigator(
key: widget.navigatorKey,
onGenerateRoute: (settings) => CupertinoPageRoute<Widget>(
builder: (_) {
final arg = settings.arguments;
if (arg == null || arg is! SurveyState) {
return widget.loadingState ??
const Center(
child: CircularProgressIndicator.adaptive(),
),
);
}

final state = settings.arguments! as SurveyState;

final step = state.currentStep;
return scaffold(
_SurveyView(
id: step!.id,
);
}
final state = settings.arguments! as SurveyState;

final step = state.currentStep;
return _SurveyView(
key: ValueKey<String>(
step!.id,
),
id: step.id,
decoration: widget.decoration,
createView: () => AnswerView(
answer: step.answerFormat,
step: step,
stepResult: state.questionResults.firstWhereOrNull(
(element) => element.id == step.id,
),
),
),
);
},
);
},
),
),
);
}
}

class _SurveyView extends StatelessWidget {
const _SurveyView({
super.key,
required this.id,
required this.createView,
this.decoration,
});

final String id;
final Widget Function() createView;
final Decoration? decoration;

@override
Widget build(BuildContext context) {
return Container(
key: ValueKey<String>(
id,
),
return DecoratedBox(
decoration: decoration ??
const BoxDecoration(
color: Colors.white,
),
child: createView(),
);
}
Expand Down

0 comments on commit 7f38c56

Please sign in to comment.