Skip to content

Commit

Permalink
feat: ✨ on functions returns a bool to check if it should continue or…
Browse files Browse the repository at this point in the history
… not (#113)
  • Loading branch information
edlose16b committed May 15, 2023
1 parent 9cafab0 commit 79d28dd
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions lib/src/controller/survey_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,46 @@ import 'package:survey_kit/src/result/question_result.dart';

class SurveyController {
/// Defines what should happen if the next step is called
/// Default behavior is:
/// ```dart
/// BlocProvider.of<SurveyPresenter>(context).add(
/// NextStep(
/// resultFunction.call(),
/// ),
/// );
/// ```
final Function(
///
/// If the function returns `true`, the default behavior will still be executed after it.
///
/// Parameters:
/// - [context]: The build context of the widget triggering the next step.
/// - [resultFunction]: A function that returns a [QuestionResult] object.
///
/// Returns:
/// - `true` if the default behavior should still be executed after this function, `false` otherwise.
final bool Function(
BuildContext context,
QuestionResult Function() resultFunction,
)? onNextStep;

/// Defines what should happen if the previous step is called
/// Default behavior is:
/// ```dart
/// BlocProvider.of<SurveyPresenter>(context).add(
/// StepBack(
/// resultFunction.call(),
/// ),
/// );
/// ```
final Function(
/// Defines what should happen if the previus step is called
///
/// If the function returns `true`, the default behavior will still be executed after it.
///
/// Parameters:
/// - [context]: The build context of the widget triggering the next step.
/// - [resultFunction]: A function that returns a [QuestionResult] object.
///
/// Returns:
/// - `true` if the default behavior should still be executed after this function, `false` otherwise.
final bool Function(
BuildContext context,
QuestionResult Function()? resultFunction,
)? onStepBack;

/// Defines what should happen if the survey should be closed
/// Default behavior is:
/// ```dart
/// BlocProvider.of<SurveyPresenter>(context).add(
/// CloseSurvey(
/// resultFunction.call(),
/// ),
/// );
/// ```
final Function(
///
/// If the function returns `true`, the default behavior will still be executed after it.
///
/// Parameters:
/// - [context]: The build context of the widget triggering the next step.
/// - [resultFunction]: A function that returns a [QuestionResult] object.
///
/// Returns:
/// - `true` if the default behavior should still be executed after this function, `false` otherwise.
final bool Function(
BuildContext context,
QuestionResult Function()? resultFunction,
)? onCloseSurvey;
Expand All @@ -58,8 +61,7 @@ class SurveyController {
QuestionResult Function() resultFunction,
) {
if (onNextStep != null) {
onNextStep!(context, resultFunction);
return;
if (!onNextStep!(context, resultFunction)) return;
}
BlocProvider.of<SurveyPresenter>(context).add(
NextStep(
Expand All @@ -73,8 +75,7 @@ class SurveyController {
QuestionResult Function()? resultFunction,
}) {
if (onStepBack != null) {
onStepBack!(context, resultFunction);
return;
if (!onStepBack!(context, resultFunction)) return;
}
BlocProvider.of<SurveyPresenter>(context).add(
StepBack(
Expand All @@ -88,8 +89,7 @@ class SurveyController {
QuestionResult Function()? resultFunction,
}) {
if (onCloseSurvey != null) {
onCloseSurvey!(context, resultFunction);
return;
if (!onCloseSurvey!(context, resultFunction)) return;
}
BlocProvider.of<SurveyPresenter>(context).add(
CloseSurvey(
Expand Down

0 comments on commit 79d28dd

Please sign in to comment.