Skip to content

Commit

Permalink
feat: allow overriding loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
Numoy committed Sep 19, 2023
1 parent b80849d commit bf53b09
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 1 addition & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,13 @@ linter:
- flutter_style_todos
- hash_and_equals
- implementation_imports
- iterable_contains_unrelated_type
- collection_methods_unrelated_type
- join_return_with_assignment
- leading_newlines_in_multiline_strings
- library_names
- library_prefixes
# - library_private_types_in_public_api
# - lines_longer_than_80_chars
- list_remove_unrelated_type
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
Expand Down
15 changes: 11 additions & 4 deletions lib/src/survey_kit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class SurveyKit extends StatefulWidget {
/// Decoration which is applied to the survey container
final BoxDecoration? decoration;

/// Widget which is shown while the survey is loading (isLoading = true)
final Widget? loadingState;

const SurveyKit({
super.key,
required this.task,
Expand All @@ -47,6 +50,7 @@ class SurveyKit extends StatefulWidget {
this.localizations,
this.stepShell,
this.decoration,
this.loadingState,
});

@override
Expand Down Expand Up @@ -104,6 +108,7 @@ class _SurveyKitState extends State<SurveyKit> {
appBar: widget.appBar,
navigatorKey: _navigatorKey,
decoration: widget.decoration,
loadingState: widget.loadingState,
);
},
),
Expand All @@ -117,6 +122,7 @@ class SurveyPage extends StatefulWidget {
final PreferredSizeWidget? appBar;
final GlobalKey<NavigatorState> navigatorKey;
final Decoration? decoration;
final Widget? loadingState;

const SurveyPage({
super.key,
Expand All @@ -125,6 +131,7 @@ class SurveyPage extends StatefulWidget {
required this.navigatorKey,
this.appBar,
this.decoration,
this.loadingState,
});

@override
Expand All @@ -145,7 +152,6 @@ class _SurveyPageState extends State<SurveyPage>

@override
Widget build(BuildContext context) {
print('Rebuild survey page');
Widget scaffold(Widget child) => Scaffold(
appBar: widget.appBar ?? const SurveyAppBar(),
body: Container(
Expand All @@ -160,9 +166,10 @@ class _SurveyPageState extends State<SurveyPage>
builder: (_) {
if (settings.arguments is! SurveyState) {
return scaffold(
const Center(
child: CircularProgressIndicator.adaptive(),
),
widget.loadingState ??
const Center(
child: CircularProgressIndicator.adaptive(),
),
);
}

Expand Down

0 comments on commit bf53b09

Please sign in to comment.