From 3b9d51f49f456c990e40a1283f16133b4b37fd8b Mon Sep 17 00:00:00 2001 From: rinzin Date: Fri, 22 Nov 2024 10:45:53 +0100 Subject: [PATCH] add analysis issue fix --- .gitignore | 4 + analysis_option.yaml | 233 ------------------ analysis_options.yaml | 21 ++ android/local.properties | 4 +- example/lib/main.dart | 2 +- example/linux/.gitignore | 2 +- example/pubspec.lock | 4 +- ios/Flutter/Generated.xcconfig | 8 +- ios/Flutter/flutter_export_environment.sh | 8 +- .../agreement_answer_format.dart | 3 +- .../agreement_answer_format.g.dart | 10 +- .../answer_format/boolean_answer_format.dart | 5 +- .../boolean_answer_format.g.dart | 8 +- lib/src/answer_format/date_answer_format.dart | 1 + .../answer_format/double_answer_format.dart | 1 + .../answer_format/image_answer_format.dart | 1 + .../answer_format/integer_answer_format.dart | 1 + .../integer_answer_format.g.dart | 2 +- lib/src/answer_format/multi_double.dart | 5 +- .../multiple_choice_answer_format.dart | 3 +- .../multiple_choice_answer_format.g.dart | 2 +- ...le_choice_auto_complete_answer_format.dart | 5 +- .../multiple_double_answer_format.dart | 3 +- .../answer_format/scale_answer_format.dart | 1 + .../single_choice_answer_format.dart | 1 + lib/src/answer_format/text_answer_format.dart | 5 +- .../answer_format/text_answer_format.g.dart | 2 +- lib/src/answer_format/text_choice.dart | 5 +- .../answer_format/time_answer_formart.dart | 1 + lib/src/controller/survey_controller.dart | 4 +- .../navigator/navigable_task_navigator.dart | 3 +- lib/src/navigator/ordered_task_navigator.dart | 3 +- .../rules/conditional_navigation_rule.dart | 1 + .../rules/direct_navigation_rule.dart | 1 + lib/src/navigator/task_navigator.dart | 4 +- lib/src/presenter/survey_presenter.dart | 38 ++- .../question/agreement_question_result.dart | 20 +- .../question/agreement_question_result.g.dart | 6 +- .../question/boolean_question_result.dart | 20 +- .../question/boolean_question_result.g.dart | 6 +- .../result/question/date_question_result.dart | 20 +- .../question/double_question_result.dart | 20 +- .../question/image_question_result.dart | 20 +- .../question/integer_question_result.dart | 20 +- .../question/integer_question_result.g.dart | 2 +- .../multiple_choice_question_result.dart | 20 +- .../multiple_double_question_result.dart | 20 +- .../question/scale_question_result.dart | 20 +- .../single_choice_question_result.dart | 20 +- .../result/question/text_question_result.dart | 20 +- .../result/question/time_question_result.dart | 35 ++- lib/src/result/question_result.dart | 11 +- lib/src/result/result.dart | 2 +- .../result/step/completion_step_result.dart | 2 +- .../result/step/instruction_step_result.dart | 2 +- lib/src/result/step/video_step_result.dart | 12 +- lib/src/result/step/video_step_result.g.dart | 2 +- lib/src/result/step_result.dart | 11 +- lib/src/result/survey/survey_result.dart | 20 +- lib/src/result/survey/survey_result.g.dart | 8 +- lib/src/steps/identifier/identifier.dart | 4 +- lib/src/steps/identifier/step_identifier.dart | 7 +- .../predefined_steps/completion_step.dart | 34 +-- .../predefined_steps/instruction_step.dart | 27 +- .../steps/predefined_steps/question_step.dart | 18 +- lib/src/steps/step.dart | 12 +- lib/src/survey_kit.dart | 6 +- lib/src/task/identifier/task_identifier.dart | 3 +- lib/src/task/navigable_task.dart | 9 +- lib/src/task/ordered_task.dart | 7 +- lib/src/task/task.dart | 10 +- lib/src/views/agreement_answer_view.dart | 20 +- lib/src/views/boolean_answer_view.dart | 24 +- lib/src/views/completion_view.dart | 4 +- lib/src/views/date_answer_view.dart | 10 +- lib/src/views/double_answer_view.dart | 11 +- lib/src/views/image_answer_view.dart | 12 +- lib/src/views/instruction_view.dart | 2 +- lib/src/views/integer_answer_view.dart | 13 +- .../multiple_auto_complete_answer_view.dart | 14 +- .../views/multiple_choice_answer_view.dart | 46 ++-- .../views/multiple_double_answer_view.dart | 6 +- lib/src/views/scale_answer_view.dart | 6 +- lib/src/views/single_choice_answer_view.dart | 8 +- lib/src/views/text_answer_view.dart | 10 +- lib/src/views/time_answer_view.dart | 10 +- lib/src/views/widget/selection_list_tile.dart | 6 +- lib/src/views/widget/step_view.dart | 6 +- lib/src/views/widget/survey_app_bar.dart | 10 +- lib/src/views/widget/time_picker_widget.dart | 27 +- lib/src/widget/survey_progress.dart | 2 +- pubspec.lock | 20 +- pubspec.yaml | 32 +-- .../boolean_question_result_test.dart | 2 +- test/src/survey/survey_result_test.dart | 4 +- test/surveykit_flutter_test.dart | 2 +- test/views/date_answer_view_test.dart | 6 +- 97 files changed, 448 insertions(+), 746 deletions(-) delete mode 100644 analysis_option.yaml create mode 100644 analysis_options.yaml diff --git a/.gitignore b/.gitignore index ec275280..d7c48010 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,7 @@ app.*.map.json /android/app/debug /android/app/profile /android/app/release + + +# FVM related +.fvmrc \ No newline at end of file diff --git a/analysis_option.yaml b/analysis_option.yaml deleted file mode 100644 index 7febab12..00000000 --- a/analysis_option.yaml +++ /dev/null @@ -1,233 +0,0 @@ -# Specify analysis options. -# -# Until there are meta linter rules, each desired lint must be explicitly enabled. -# See: https://github.com/dart-lang/linter/issues/288 -# -# For a list of lints, see: http://dart-lang.github.io/linter/lints/ -# See the configuration guide for more -# https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer -# -# There are other similar analysis options files in the flutter repos, -# which should be kept in sync with this file: -# -# - analysis_options.yaml (this file) -# - packages/flutter/lib/analysis_options_user.yaml -# - https://github.com/flutter/plugins/blob/master/analysis_options.yaml -# - https://github.com/flutter/engine/blob/master/analysis_options.yaml -# -# This file contains the analysis options used by Flutter tools, such as IntelliJ, -# Android Studio, and the `flutter analyze` command. -include: package:extra_pedantic/analysis_options.yaml - -exclude: - - "**/*.g.dart" - -analyzer: - strong-mode: - implicit-casts: false - implicit-dynamic: false - errors: - # treat missing required parameters as a warning (not a hint) - missing_required_param: warning - # treat missing returns as a warning (not a hint) - missing_return: warning - # allow having TODOs in the code - todo: ignore - # allow self-reference to deprecated members (we do this because otherwise we have - # to annotate every member in every test, assert, etc, when we deprecate something) - deprecated_member_use_from_same_package: ignore - # Ignore analyzer hints for updating pubspecs when using Future or - # Stream and not importing dart:async - # Please see https://github.com/flutter/flutter/pull/24528 for details. - sdk_version_async_exported_from_core: ignore - exclude: - - "bin/cache/**" - # the following two are relative to the stocks example and the flutter package respectively - # see https://github.com/dart-lang/sdk/issues/28463 - - "lib/i18n/messages_*.dart" - - "lib/src/http/**" - - "test_fixes/**" - -linter: - rules: - # these rules are documented on and in the same order as - # the Dart Lint rules page to make maintenance easier - # https://github.com/dart-lang/linter/blob/master/example/all.yaml - - always_declare_return_types - - always_put_control_body_on_new_line - # - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219 - - always_require_non_null_named_parameters - - always_specify_types - # - always_use_package_imports # we do this commonly - - annotate_overrides - # - avoid_annotating_with_dynamic # conflicts with always_specify_types - # - avoid_as # required for implicit-casts: true - - avoid_bool_literals_in_conditional_expressions - # - avoid_catches_without_on_clauses # we do this commonly - # - avoid_catching_errors # we do this commonly - - avoid_classes_with_only_static_members - # - avoid_double_and_int_checks # only useful when targeting JS runtime - - avoid_empty_else - - avoid_equals_and_hash_code_on_mutable_classes - # - avoid_escaping_inner_quotes # not yet tested - - avoid_field_initializers_in_const_classes - - avoid_function_literals_in_foreach_calls - # - avoid_implementing_value_types # not yet tested - - avoid_init_to_null - # - avoid_js_rounded_ints # only useful when targeting JS runtime - - avoid_null_checks_in_equality_operators - # - avoid_positional_boolean_parameters # not yet tested - # - avoid_print # not yet tested - # - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356) - # - avoid_redundant_argument_values # not yet tested - - avoid_relative_lib_imports - - avoid_renaming_method_parameters - - avoid_return_types_on_setters - # - avoid_returning_null # there are plenty of valid reasons to return null - # - avoid_returning_null_for_future # not yet tested - - avoid_returning_null_for_void - # - avoid_returning_this # there are plenty of valid reasons to return this - # - avoid_setters_without_getters # not yet tested - - avoid_shadowing_type_parameters - - avoid_single_cascade_in_expression_statements - - avoid_slow_async_io - # - avoid_type_to_string # we do this commonly - - avoid_types_as_parameter_names - # - avoid_types_on_closure_parameters # conflicts with always_specify_types - # - avoid_unnecessary_containers # not yet tested - - avoid_unused_constructor_parameters - - avoid_void_async - # - avoid_web_libraries_in_flutter # not yet tested - - await_only_futures - - camel_case_extensions - - camel_case_types - - cancel_subscriptions - # - cascade_invocations # not yet tested - - cast_nullable_to_non_nullable - # - close_sinks # not reliable enough - # - comment_references # blocked on https://github.com/flutter/flutter/issues/20765 - # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204 - - control_flow_in_finally - # - curly_braces_in_flow_control_structures # not required by flutter style - # - diagnostic_describe_all_properties # not yet tested - - directives_ordering - # - do_not_use_environment # we do this commonly - - empty_catches - - empty_constructor_bodies - - empty_statements - - exhaustive_cases - # - file_names # not yet tested - - flutter_style_todos - - hash_and_equals - - implementation_imports - # - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811 - - iterable_contains_unrelated_type - # - join_return_with_assignment # not required by flutter style - - leading_newlines_in_multiline_strings - - library_names - - library_prefixes - # - lines_longer_than_80_chars # not required by flutter style - - list_remove_unrelated_type - # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181 - # - missing_whitespace_between_adjacent_strings # not yet tested - - no_adjacent_strings_in_list - # - no_default_cases # too many false positives - - no_duplicate_case_values - - no_logic_in_create_state - # - no_runtimeType_toString # ok in tests; we enable this only in packages/ - - non_constant_identifier_names - - null_check_on_nullable_type_parameter - # - null_closures # not required by flutter style - # - omit_local_variable_types # opposite of always_specify_types - # - one_member_abstracts # too many false positives - # - only_throw_errors # https://github.com/flutter/flutter/issues/5792 - - overridden_fields - - package_api_docs - # - package_names # non conforming packages in sdk - - package_prefixed_library_names - # - parameter_assignments # we do this commonly - - prefer_adjacent_string_concatenation - - prefer_asserts_in_initializer_lists - # - prefer_asserts_with_message # not required by flutter style - - prefer_collection_literals - - prefer_conditional_assignment - - prefer_const_constructors - - prefer_const_constructors_in_immutables - - prefer_const_declarations - - prefer_const_literals_to_create_immutables - # - prefer_constructors_over_static_methods # far too many false positives - - prefer_contains - # - prefer_double_quotes # opposite of prefer_single_quotes - - prefer_equal_for_default_values - # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods - - prefer_final_fields - - prefer_final_in_for_each - - prefer_final_locals - - prefer_for_elements_to_map_fromIterable - - prefer_foreach - # - prefer_function_declarations_over_variables # not yet tested - - prefer_generic_function_type_aliases - - prefer_if_elements_to_conditional_expressions - - prefer_if_null_operators - - prefer_initializing_formals - - prefer_inlined_adds - # - prefer_int_literals # not yet tested - # - prefer_interpolation_to_compose_strings # not yet tested - - prefer_is_empty - - prefer_is_not_empty - - prefer_is_not_operator - - prefer_iterable_whereType - # - prefer_mixin # https://github.com/dart-lang/language/issues/32 - # - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932 - # - prefer_relative_imports # not yet tested - - prefer_single_quotes - - prefer_spread_collections - - prefer_typing_uninitialized_variables - - prefer_void_to_null - # - provide_deprecation_message # not yet tested - # - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml - - recursive_getters - # - sized_box_for_whitespace # not yet tested - - slash_for_doc_comments - # - sort_child_properties_last # not yet tested - - sort_constructors_first - # - sort_pub_dependencies # prevents separating pinned transitive dependencies - - sort_unnamed_constructors_first - - test_types_in_equals - - throw_in_finally - - tighten_type_of_initializing_formals - # - type_annotate_public_apis # subset of always_specify_types - - type_init_formals - # - unawaited_futures # too many false positives - # - unnecessary_await_in_return # not yet tested - - unnecessary_brace_in_string_interps - - unnecessary_const - # - unnecessary_final # conflicts with prefer_final_locals - - unnecessary_getters_setters - # - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498 - - unnecessary_new - - unnecessary_null_aware_assignments - # - unnecessary_null_checks # not yet tested - - unnecessary_null_in_if_null_operators - - unnecessary_nullable_for_final_variable_declarations - - unnecessary_overrides - - unnecessary_parenthesis - # - unnecessary_raw_strings # not yet tested - - unnecessary_statements - - unnecessary_string_escapes - - unnecessary_string_interpolations - - unnecessary_this - - unrelated_type_equality_checks - # - unsafe_html # not yet tested - - use_full_hex_values_for_flutter_colors - # - use_function_type_syntax_for_parameters # not yet tested - - use_is_even_rather_than_modulo - # - use_key_in_widget_constructors # not yet tested - - use_late_for_private_fields_and_variables - - use_raw_strings - - use_rethrow_when_possible - # - use_setters_to_change_properties # not yet tested - # - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182 - # - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review - - valid_regexps - - void_checks \ No newline at end of file diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 00000000..b135a279 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,21 @@ +include: package:flutter_lints/flutter.yaml + +analyzer: + errors: + close_sinks: ignore + missing_required_param: error + missing_return: error + # Ignored because of freezed and JsonKey (https://github.com/rrousselGit/freezed/issues/488) + invalid_annotation_target: ignore + body_might_complete_normally_nullable: ignore + depend_on_referenced_packages: ignore + avoid_function_literals_in_foreach_calls: ignore + + exclude: + - test/.test_coverage.dart + - lib/generated_plugin_registrant.dart + - "**/*.g.dart" + - "**/*.freezed.dart" + +linter: + rules: diff --git a/android/local.properties b/android/local.properties index 59210e88..8687ec82 100644 --- a/android/local.properties +++ b/android/local.properties @@ -1,2 +1,2 @@ -sdk.dir=/Users/marvin/Library/Android/sdk -flutter.sdk=/Users/marvin/flutter \ No newline at end of file +sdk.dir=/Users/rinzin/Library/Android/sdk +flutter.sdk=/Users/rinzin/fvm/versions/3.24.0 \ No newline at end of file diff --git a/example/lib/main.dart b/example/lib/main.dart index 94aabc04..9c56e2de 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -189,7 +189,7 @@ class _MyAppState extends State { answerFormat: const BooleanAnswerFormat( positiveAnswer: 'Yes', negativeAnswer: 'No', - result: BooleanResult.POSITIVE, + result: BooleanResult.positive, ), ), QuestionStep( diff --git a/example/linux/.gitignore b/example/linux/.gitignore index d3896c98..229c1099 100644 --- a/example/linux/.gitignore +++ b/example/linux/.gitignore @@ -1 +1 @@ -flutter/ephemeral +flutter/ephemeral/ diff --git a/example/pubspec.lock b/example/pubspec.lock index 8865cbbf..19f339cc 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -703,10 +703,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc url: "https://pub.dev" source: hosted - version: "14.2.5" + version: "14.2.4" web: dependency: transitive description: diff --git a/ios/Flutter/Generated.xcconfig b/ios/Flutter/Generated.xcconfig index 5c0a4519..22d253a4 100644 --- a/ios/Flutter/Generated.xcconfig +++ b/ios/Flutter/Generated.xcconfig @@ -1,11 +1,11 @@ // This is a generated file; do not edit or check into version control. -FLUTTER_ROOT=/Users/marvin/flutter -FLUTTER_APPLICATION_PATH=/Users/marvin/repositories/survey_kit +FLUTTER_ROOT=/Users/rinzin/fvm/versions/3.24.0 +FLUTTER_APPLICATION_PATH=/Users/rinzin/qbs/survey_kit COCOAPODS_PARALLEL_CODE_SIGN=true FLUTTER_TARGET=lib/main.dart FLUTTER_BUILD_DIR=build -FLUTTER_BUILD_NAME=0.1.2 -FLUTTER_BUILD_NUMBER=0.1.2 +FLUTTER_BUILD_NAME=0.2.1 +FLUTTER_BUILD_NUMBER=0.2.1 EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386 EXCLUDED_ARCHS[sdk=iphoneos*]=armv7 DART_OBFUSCATION=false diff --git a/ios/Flutter/flutter_export_environment.sh b/ios/Flutter/flutter_export_environment.sh index 9c4d43f7..990b6c9e 100755 --- a/ios/Flutter/flutter_export_environment.sh +++ b/ios/Flutter/flutter_export_environment.sh @@ -1,12 +1,12 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=/Users/marvin/flutter" -export "FLUTTER_APPLICATION_PATH=/Users/marvin/repositories/survey_kit" +export "FLUTTER_ROOT=/Users/rinzin/fvm/versions/3.24.0" +export "FLUTTER_APPLICATION_PATH=/Users/rinzin/qbs/survey_kit" export "COCOAPODS_PARALLEL_CODE_SIGN=true" export "FLUTTER_TARGET=lib/main.dart" export "FLUTTER_BUILD_DIR=build" -export "FLUTTER_BUILD_NAME=0.1.2" -export "FLUTTER_BUILD_NUMBER=0.1.2" +export "FLUTTER_BUILD_NAME=0.2.1" +export "FLUTTER_BUILD_NUMBER=0.2.1" export "DART_OBFUSCATION=false" export "TRACK_WIDGET_CREATION=true" export "TREE_SHAKE_ICONS=false" diff --git a/lib/src/answer_format/agreement_answer_format.dart b/lib/src/answer_format/agreement_answer_format.dart index 21ebc6df..8c465c97 100644 --- a/lib/src/answer_format/agreement_answer_format.dart +++ b/lib/src/answer_format/agreement_answer_format.dart @@ -12,7 +12,7 @@ class AgreementAnswerFormat implements AnswerFormat { final String? markdownAgreementText; const AgreementAnswerFormat({ - this.result = BooleanResult.NEGATIVE, + this.result = BooleanResult.negative, this.defaultValue, this.markdownDescription, this.markdownAgreementText, @@ -20,5 +20,6 @@ class AgreementAnswerFormat implements AnswerFormat { factory AgreementAnswerFormat.fromJson(Map json) => _$AgreementAnswerFormatFromJson(json); + @override Map toJson() => _$AgreementAnswerFormatToJson(this); } diff --git a/lib/src/answer_format/agreement_answer_format.g.dart b/lib/src/answer_format/agreement_answer_format.g.dart index 0fd11104..7431692b 100644 --- a/lib/src/answer_format/agreement_answer_format.g.dart +++ b/lib/src/answer_format/agreement_answer_format.g.dart @@ -10,7 +10,7 @@ AgreementAnswerFormat _$AgreementAnswerFormatFromJson( Map json) => AgreementAnswerFormat( result: $enumDecodeNullable(_$BooleanResultEnumMap, json['result']) ?? - BooleanResult.NEGATIVE, + BooleanResult.negative, defaultValue: $enumDecodeNullable(_$BooleanResultEnumMap, json['defaultValue']), markdownDescription: json['markdownDescription'] as String?, @@ -20,14 +20,14 @@ AgreementAnswerFormat _$AgreementAnswerFormatFromJson( Map _$AgreementAnswerFormatToJson( AgreementAnswerFormat instance) => { - 'result': _$BooleanResultEnumMap[instance.result], + 'result': _$BooleanResultEnumMap[instance.result]!, 'defaultValue': _$BooleanResultEnumMap[instance.defaultValue], 'markdownDescription': instance.markdownDescription, 'markdownAgreementText': instance.markdownAgreementText, }; const _$BooleanResultEnumMap = { - BooleanResult.NONE: 'NONE', - BooleanResult.POSITIVE: 'POSITIVE', - BooleanResult.NEGATIVE: 'NEGATIVE', + BooleanResult.none: 'none', + BooleanResult.positive: 'positive', + BooleanResult.negative: 'negative', }; diff --git a/lib/src/answer_format/boolean_answer_format.dart b/lib/src/answer_format/boolean_answer_format.dart index 136de785..40bc6ba2 100644 --- a/lib/src/answer_format/boolean_answer_format.dart +++ b/lib/src/answer_format/boolean_answer_format.dart @@ -13,13 +13,14 @@ class BooleanAnswerFormat implements AnswerFormat { const BooleanAnswerFormat({ required this.positiveAnswer, required this.negativeAnswer, - this.result = BooleanResult.NONE, + this.result = BooleanResult.none, this.defaultValue, }) : super(); factory BooleanAnswerFormat.fromJson(Map json) => _$BooleanAnswerFormatFromJson(json); + @override Map toJson() => _$BooleanAnswerFormatToJson(this); } -enum BooleanResult { NONE, POSITIVE, NEGATIVE } +enum BooleanResult { none, positive, negative } diff --git a/lib/src/answer_format/boolean_answer_format.g.dart b/lib/src/answer_format/boolean_answer_format.g.dart index d8c735c0..1b1e7d10 100644 --- a/lib/src/answer_format/boolean_answer_format.g.dart +++ b/lib/src/answer_format/boolean_answer_format.g.dart @@ -11,7 +11,7 @@ BooleanAnswerFormat _$BooleanAnswerFormatFromJson(Map json) => positiveAnswer: json['positiveAnswer'] as String, negativeAnswer: json['negativeAnswer'] as String, result: $enumDecodeNullable(_$BooleanResultEnumMap, json['result']) ?? - BooleanResult.NONE, + BooleanResult.none, defaultValue: $enumDecodeNullable(_$BooleanResultEnumMap, json['defaultValue']), ); @@ -26,7 +26,7 @@ Map _$BooleanAnswerFormatToJson( }; const _$BooleanResultEnumMap = { - BooleanResult.NONE: 'NONE', - BooleanResult.POSITIVE: 'POSITIVE', - BooleanResult.NEGATIVE: 'NEGATIVE', + BooleanResult.none: 'none', + BooleanResult.positive: 'positive', + BooleanResult.negative: 'negative', }; diff --git a/lib/src/answer_format/date_answer_format.dart b/lib/src/answer_format/date_answer_format.dart index afd4ca3e..3c32cc58 100644 --- a/lib/src/answer_format/date_answer_format.dart +++ b/lib/src/answer_format/date_answer_format.dart @@ -31,5 +31,6 @@ class DateAnswerFormat implements AnswerFormat { factory DateAnswerFormat.fromJson(Map json) => _$DateAnswerFormatFromJson(json); + @override Map toJson() => _$DateAnswerFormatToJson(this); } diff --git a/lib/src/answer_format/double_answer_format.dart b/lib/src/answer_format/double_answer_format.dart index f3f52cb6..ac55edf6 100644 --- a/lib/src/answer_format/double_answer_format.dart +++ b/lib/src/answer_format/double_answer_format.dart @@ -17,5 +17,6 @@ class DoubleAnswerFormat implements AnswerFormat { factory DoubleAnswerFormat.fromJson(Map json) => _$DoubleAnswerFormatFromJson(json); + @override Map toJson() => _$DoubleAnswerFormatToJson(this); } diff --git a/lib/src/answer_format/image_answer_format.dart b/lib/src/answer_format/image_answer_format.dart index 73f1c670..ad38dcbb 100644 --- a/lib/src/answer_format/image_answer_format.dart +++ b/lib/src/answer_format/image_answer_format.dart @@ -23,5 +23,6 @@ class ImageAnswerFormat implements AnswerFormat { factory ImageAnswerFormat.fromJson(Map json) => _$ImageAnswerFormatFromJson(json); + @override Map toJson() => _$ImageAnswerFormatToJson(this); } diff --git a/lib/src/answer_format/integer_answer_format.dart b/lib/src/answer_format/integer_answer_format.dart index ff939bfc..7969c122 100644 --- a/lib/src/answer_format/integer_answer_format.dart +++ b/lib/src/answer_format/integer_answer_format.dart @@ -15,5 +15,6 @@ class IntegerAnswerFormat implements AnswerFormat { factory IntegerAnswerFormat.fromJson(Map json) => _$IntegerAnswerFormatFromJson(json); + @override Map toJson() => _$IntegerAnswerFormatToJson(this); } diff --git a/lib/src/answer_format/integer_answer_format.g.dart b/lib/src/answer_format/integer_answer_format.g.dart index e6e5e573..7cbdc0c6 100644 --- a/lib/src/answer_format/integer_answer_format.g.dart +++ b/lib/src/answer_format/integer_answer_format.g.dart @@ -8,7 +8,7 @@ part of 'integer_answer_format.dart'; IntegerAnswerFormat _$IntegerAnswerFormatFromJson(Map json) => IntegerAnswerFormat( - defaultValue: json['defaultValue'] as int?, + defaultValue: (json['defaultValue'] as num?)?.toInt(), hint: json['hint'] as String? ?? '', ); diff --git a/lib/src/answer_format/multi_double.dart b/lib/src/answer_format/multi_double.dart index bff53b12..bfe324b3 100644 --- a/lib/src/answer_format/multi_double.dart +++ b/lib/src/answer_format/multi_double.dart @@ -16,6 +16,9 @@ class MultiDouble { _$MultiDoubleFromJson(json); Map toJson() => _$MultiDoubleToJson(this); - bool operator ==(o) => o is MultiDouble && text == o.text && value == o.value; + @override + bool operator ==(other) => + other is MultiDouble && text == other.text && value == other.value; + @override int get hashCode => text.hashCode ^ value.hashCode; } diff --git a/lib/src/answer_format/multiple_choice_answer_format.dart b/lib/src/answer_format/multiple_choice_answer_format.dart index b9641323..5525dd5c 100644 --- a/lib/src/answer_format/multiple_choice_answer_format.dart +++ b/lib/src/answer_format/multiple_choice_answer_format.dart @@ -7,7 +7,7 @@ part 'multiple_choice_answer_format.g.dart'; @JsonSerializable() class MultipleChoiceAnswerFormat implements AnswerFormat { final List textChoices; - @JsonKey(defaultValue: const []) + @JsonKey(defaultValue: []) final List defaultSelection; @JsonKey(defaultValue: false) final bool otherField; @@ -23,5 +23,6 @@ class MultipleChoiceAnswerFormat implements AnswerFormat { factory MultipleChoiceAnswerFormat.fromJson(Map json) => _$MultipleChoiceAnswerFormatFromJson(json); + @override Map toJson() => _$MultipleChoiceAnswerFormatToJson(this); } diff --git a/lib/src/answer_format/multiple_choice_answer_format.g.dart b/lib/src/answer_format/multiple_choice_answer_format.g.dart index 39434efa..54994bad 100644 --- a/lib/src/answer_format/multiple_choice_answer_format.g.dart +++ b/lib/src/answer_format/multiple_choice_answer_format.g.dart @@ -17,7 +17,7 @@ MultipleChoiceAnswerFormat _$MultipleChoiceAnswerFormatFromJson( .toList() ?? [], otherField: json['otherField'] as bool? ?? false, - maxAnswers: json['maxAnswers'] as int? ?? 100, + maxAnswers: (json['maxAnswers'] as num?)?.toInt() ?? 100, ); Map _$MultipleChoiceAnswerFormatToJson( diff --git a/lib/src/answer_format/multiple_choice_auto_complete_answer_format.dart b/lib/src/answer_format/multiple_choice_auto_complete_answer_format.dart index a0400631..af9cd4f3 100644 --- a/lib/src/answer_format/multiple_choice_auto_complete_answer_format.dart +++ b/lib/src/answer_format/multiple_choice_auto_complete_answer_format.dart @@ -7,9 +7,9 @@ part 'multiple_choice_auto_complete_answer_format.g.dart'; @JsonSerializable() class MultipleChoiceAutoCompleteAnswerFormat implements AnswerFormat { final List textChoices; - @JsonKey(defaultValue: const []) + @JsonKey(defaultValue: []) final List defaultSelection; - @JsonKey(defaultValue: const []) + @JsonKey(defaultValue: []) final List suggestions; @JsonKey(defaultValue: false) final bool otherField; @@ -24,6 +24,7 @@ class MultipleChoiceAutoCompleteAnswerFormat implements AnswerFormat { factory MultipleChoiceAutoCompleteAnswerFormat.fromJson( Map json) => _$MultipleChoiceAutoCompleteAnswerFormatFromJson(json); + @override Map toJson() => _$MultipleChoiceAutoCompleteAnswerFormatToJson(this); } diff --git a/lib/src/answer_format/multiple_double_answer_format.dart b/lib/src/answer_format/multiple_double_answer_format.dart index 3e4395d2..7b278a04 100644 --- a/lib/src/answer_format/multiple_double_answer_format.dart +++ b/lib/src/answer_format/multiple_double_answer_format.dart @@ -7,7 +7,7 @@ part 'multiple_double_answer_format.g.dart'; @JsonSerializable() class MultipleDoubleAnswerFormat implements AnswerFormat { final List? defaultValues; - @JsonKey(defaultValue: const []) + @JsonKey(defaultValue: []) final List hints; const MultipleDoubleAnswerFormat({ @@ -17,5 +17,6 @@ class MultipleDoubleAnswerFormat implements AnswerFormat { factory MultipleDoubleAnswerFormat.fromJson(Map json) => _$MultipleDoubleAnswerFormatFromJson(json); + @override Map toJson() => _$MultipleDoubleAnswerFormatToJson(this); } diff --git a/lib/src/answer_format/scale_answer_format.dart b/lib/src/answer_format/scale_answer_format.dart index df532537..d7278165 100644 --- a/lib/src/answer_format/scale_answer_format.dart +++ b/lib/src/answer_format/scale_answer_format.dart @@ -25,5 +25,6 @@ class ScaleAnswerFormat implements AnswerFormat { factory ScaleAnswerFormat.fromJson(Map json) => _$ScaleAnswerFormatFromJson(json); + @override Map toJson() => _$ScaleAnswerFormatToJson(this); } diff --git a/lib/src/answer_format/single_choice_answer_format.dart b/lib/src/answer_format/single_choice_answer_format.dart index f1a1055a..4380f8ef 100644 --- a/lib/src/answer_format/single_choice_answer_format.dart +++ b/lib/src/answer_format/single_choice_answer_format.dart @@ -16,5 +16,6 @@ class SingleChoiceAnswerFormat implements AnswerFormat { factory SingleChoiceAnswerFormat.fromJson(Map json) => _$SingleChoiceAnswerFormatFromJson(json); + @override Map toJson() => _$SingleChoiceAnswerFormatToJson(this); } diff --git a/lib/src/answer_format/text_answer_format.dart b/lib/src/answer_format/text_answer_format.dart index ae2e97f8..61d503e8 100644 --- a/lib/src/answer_format/text_answer_format.dart +++ b/lib/src/answer_format/text_answer_format.dart @@ -15,17 +15,18 @@ class TextAnswerFormat implements AnswerFormat { /// to allow any type of an answer including an empty one; /// set it explicitly to null. /// - @JsonKey(defaultValue: '^(?!\s*\$).+') + @JsonKey(defaultValue: '^(?!s*\$).+') final String? validationRegEx; const TextAnswerFormat({ this.maxLines, this.hint = '', this.defaultValue, - this.validationRegEx = '^(?!\s*\$).+', + this.validationRegEx = '^(?!s*\$).+', }) : super(); factory TextAnswerFormat.fromJson(Map json) => _$TextAnswerFormatFromJson(json); + @override Map toJson() => _$TextAnswerFormatToJson(this); } diff --git a/lib/src/answer_format/text_answer_format.g.dart b/lib/src/answer_format/text_answer_format.g.dart index 8dd7b607..7b90d18e 100644 --- a/lib/src/answer_format/text_answer_format.g.dart +++ b/lib/src/answer_format/text_answer_format.g.dart @@ -8,7 +8,7 @@ part of 'text_answer_format.dart'; TextAnswerFormat _$TextAnswerFormatFromJson(Map json) => TextAnswerFormat( - maxLines: json['maxLines'] as int?, + maxLines: (json['maxLines'] as num?)?.toInt(), hint: json['hint'] as String? ?? '', defaultValue: json['defaultValue'] as String?, validationRegEx: json['validationRegEx'] as String? ?? r'^(?!s*$).+', diff --git a/lib/src/answer_format/text_choice.dart b/lib/src/answer_format/text_choice.dart index f9b56c8a..d8186bcf 100644 --- a/lib/src/answer_format/text_choice.dart +++ b/lib/src/answer_format/text_choice.dart @@ -16,6 +16,9 @@ class TextChoice { _$TextChoiceFromJson(json); Map toJson() => _$TextChoiceToJson(this); - bool operator ==(o) => o is TextChoice && text == o.text && value == o.value; + @override + bool operator ==(other) => + other is TextChoice && text == other.text && value == other.value; + @override int get hashCode => text.hashCode ^ value.hashCode; } diff --git a/lib/src/answer_format/time_answer_formart.dart b/lib/src/answer_format/time_answer_formart.dart index 5516568c..95b47fd7 100644 --- a/lib/src/answer_format/time_answer_formart.dart +++ b/lib/src/answer_format/time_answer_formart.dart @@ -15,6 +15,7 @@ class TimeAnswerFormat implements AnswerFormat { factory TimeAnswerFormat.fromJson(Map json) => _$TimeAnswerFormatFromJson(json); + @override Map toJson() => _$TimeAnswerFormatToJson(this); } diff --git a/lib/src/controller/survey_controller.dart b/lib/src/controller/survey_controller.dart index 9e243ead..ce267663 100644 --- a/lib/src/controller/survey_controller.dart +++ b/lib/src/controller/survey_controller.dart @@ -79,7 +79,7 @@ class SurveyController { } BlocProvider.of(context).add( StepBack( - resultFunction != null ? resultFunction.call() : null, + resultFunction?.call(), ), ); } @@ -93,7 +93,7 @@ class SurveyController { } BlocProvider.of(context).add( CloseSurvey( - resultFunction != null ? resultFunction.call() : null, + resultFunction?.call(), ), ); } diff --git a/lib/src/navigator/navigable_task_navigator.dart b/lib/src/navigator/navigable_task_navigator.dart index 60cd97da..1b3c0476 100644 --- a/lib/src/navigator/navigable_task_navigator.dart +++ b/lib/src/navigator/navigable_task_navigator.dart @@ -5,10 +5,9 @@ import 'package:survey_kit/src/navigator/task_navigator.dart'; import 'package:survey_kit/src/result/question_result.dart'; import 'package:survey_kit/src/steps/step.dart'; import 'package:survey_kit/src/task/navigable_task.dart'; -import 'package:survey_kit/src/task/task.dart'; class NavigableTaskNavigator extends TaskNavigator { - NavigableTaskNavigator(Task task) : super(task); + NavigableTaskNavigator(super.task); @override Step? nextStep({required Step step, QuestionResult? questionResult}) { diff --git a/lib/src/navigator/ordered_task_navigator.dart b/lib/src/navigator/ordered_task_navigator.dart index e4be4706..57869760 100644 --- a/lib/src/navigator/ordered_task_navigator.dart +++ b/lib/src/navigator/ordered_task_navigator.dart @@ -1,10 +1,9 @@ import 'package:survey_kit/src/navigator/task_navigator.dart'; import 'package:survey_kit/src/result/question_result.dart'; import 'package:survey_kit/src/steps/step.dart'; -import 'package:survey_kit/src/task/task.dart'; class OrderedTaskNavigator extends TaskNavigator { - OrderedTaskNavigator(Task task) : super(task); + OrderedTaskNavigator(super.task); @override Step? nextStep({required Step step, QuestionResult? questionResult}) { diff --git a/lib/src/navigator/rules/conditional_navigation_rule.dart b/lib/src/navigator/rules/conditional_navigation_rule.dart index 3236a05e..ba6614e7 100644 --- a/lib/src/navigator/rules/conditional_navigation_rule.dart +++ b/lib/src/navigator/rules/conditional_navigation_rule.dart @@ -20,5 +20,6 @@ class ConditionalNavigationRule implements NavigationRule { ); } + @override Map toJson() => {'values': {}}; } diff --git a/lib/src/navigator/rules/direct_navigation_rule.dart b/lib/src/navigator/rules/direct_navigation_rule.dart index 07eed500..c01f8901 100644 --- a/lib/src/navigator/rules/direct_navigation_rule.dart +++ b/lib/src/navigator/rules/direct_navigation_rule.dart @@ -12,5 +12,6 @@ class DirectNavigationRule implements NavigationRule { factory DirectNavigationRule.fromJson(Map json) => _$DirectNavigationRuleFromJson(json); + @override Map toJson() => _$DirectNavigationRuleToJson(this); } diff --git a/lib/src/navigator/task_navigator.dart b/lib/src/navigator/task_navigator.dart index 693f1fcb..d48dffb6 100644 --- a/lib/src/navigator/task_navigator.dart +++ b/lib/src/navigator/task_navigator.dart @@ -45,8 +45,8 @@ abstract class TaskNavigator { // Discard count of multiple completion steps and count only one if present int get countSteps => - task.steps.where((step) => !(step is CompletionStep)).length + - (task.steps.where((step) => step is CompletionStep).isEmpty ? 0 : 1); + task.steps.where((step) => step is! CompletionStep).length + + (task.steps.whereType().isEmpty ? 0 : 1); int currentStepIndex(Step step) { return task.steps.indexOf(step); diff --git a/lib/src/presenter/survey_presenter.dart b/lib/src/presenter/survey_presenter.dart index f0390462..5ccd60f3 100644 --- a/lib/src/presenter/survey_presenter.dart +++ b/lib/src/presenter/survey_presenter.dart @@ -7,8 +7,8 @@ import 'package:survey_kit/src/presenter/survey_state.dart'; import 'package:survey_kit/src/result/question_result.dart'; import 'package:survey_kit/src/result/step_result.dart'; import 'package:survey_kit/src/result/survey/survey_result.dart'; -import 'package:survey_kit/src/steps/step.dart'; import 'package:survey_kit/src/steps/identifier/step_identifier.dart'; +import 'package:survey_kit/src/steps/step.dart'; //TO DO: Extract gathering of the results into another class class SurveyPresenter extends Bloc { @@ -22,40 +22,32 @@ class SurveyPresenter extends Bloc { required this.taskNavigator, required this.onResult, }) : super(LoadingSurveyState()) { - - on((event, emit){ - emit( - _handleInitialStep() - ); + on((event, emit) { + emit(_handleInitialStep()); }); - on((event, emit){ - if (state is PresentingSurveyState){ + on((event, emit) { + if (state is PresentingSurveyState) { emit(_handleNextStep(event, state as PresentingSurveyState)); } }); - on((event, emit){ - if (state is PresentingSurveyState){ - emit( - _handleStepBack(event, state as PresentingSurveyState) - ); + on((event, emit) { + if (state is PresentingSurveyState) { + emit(_handleStepBack(event, state as PresentingSurveyState)); } }); - on((event, emit){ - if (state is PresentingSurveyState){ - emit( - _handleClose(event, state as PresentingSurveyState) - ); + on((event, emit) { + if (state is PresentingSurveyState) { + emit(_handleClose(event, state as PresentingSurveyState)); } }); - this.startDate = DateTime.now(); + startDate = DateTime.now(); add(StartSurvey()); } - SurveyState _handleInitialStep() { Step? step = taskNavigator.firstStep(); if (step != null) { @@ -78,7 +70,7 @@ class SurveyPresenter extends Bloc { id: taskNavigator.task.id, startDate: startDate, endDate: DateTime.now(), - finishReason: FinishReason.COMPLETED, + finishReason: FinishReason.completed, results: [], ); return SurveyResultState( @@ -160,7 +152,7 @@ class SurveyPresenter extends Bloc { id: taskNavigator.task.id, startDate: startDate, endDate: DateTime.now(), - finishReason: FinishReason.DISCARDED, + finishReason: FinishReason.discarded, results: stepResults, ); return SurveyResultState( @@ -178,7 +170,7 @@ class SurveyPresenter extends Bloc { id: taskNavigator.task.id, startDate: startDate, endDate: DateTime.now(), - finishReason: FinishReason.COMPLETED, + finishReason: FinishReason.completed, results: stepResults, ); return SurveyResultState( diff --git a/lib/src/result/question/agreement_question_result.dart b/lib/src/result/question/agreement_question_result.dart index 937eb655..67b6ded1 100644 --- a/lib/src/result/question/agreement_question_result.dart +++ b/lib/src/result/question/agreement_question_result.dart @@ -8,19 +8,13 @@ part 'agreement_question_result.g.dart'; @JsonSerializable(explicitToJson: true) class AgreementQuestionResult extends QuestionResult { - AgreementQuestionResult({ - required Identifier id, - required DateTime startDate, - required DateTime endDate, - required String valueIdentifier, - required BooleanResult? result, - }) : super( - id: id, - startDate: startDate, - endDate: endDate, - valueIdentifier: valueIdentifier, - result: result, - ); + const AgreementQuestionResult({ + required Identifier super.id, + required super.startDate, + required super.endDate, + required String super.valueIdentifier, + required super.result, + }); factory AgreementQuestionResult.fromJson(Map json) => _$AgreementQuestionResultFromJson(json); diff --git a/lib/src/result/question/agreement_question_result.g.dart b/lib/src/result/question/agreement_question_result.g.dart index 192b8623..d191d7b1 100644 --- a/lib/src/result/question/agreement_question_result.g.dart +++ b/lib/src/result/question/agreement_question_result.g.dart @@ -27,7 +27,7 @@ Map _$AgreementQuestionResultToJson( }; const _$BooleanResultEnumMap = { - BooleanResult.NONE: 'NONE', - BooleanResult.POSITIVE: 'POSITIVE', - BooleanResult.NEGATIVE: 'NEGATIVE', + BooleanResult.none: 'none', + BooleanResult.positive: 'positive', + BooleanResult.negative: 'negative', }; diff --git a/lib/src/result/question/boolean_question_result.dart b/lib/src/result/question/boolean_question_result.dart index 3ff59f4d..af309fc1 100644 --- a/lib/src/result/question/boolean_question_result.dart +++ b/lib/src/result/question/boolean_question_result.dart @@ -8,19 +8,13 @@ part 'boolean_question_result.g.dart'; @JsonSerializable(explicitToJson: true) class BooleanQuestionResult extends QuestionResult { - BooleanQuestionResult({ - required Identifier id, - required DateTime startDate, - required DateTime endDate, - required String valueIdentifier, - required BooleanResult? result, - }) : super( - id: id, - startDate: startDate, - endDate: endDate, - valueIdentifier: valueIdentifier, - result: result, - ); + const BooleanQuestionResult({ + required Identifier super.id, + required super.startDate, + required super.endDate, + required String super.valueIdentifier, + required super.result, + }); factory BooleanQuestionResult.fromJson(Map json) => _$BooleanQuestionResultFromJson(json); diff --git a/lib/src/result/question/boolean_question_result.g.dart b/lib/src/result/question/boolean_question_result.g.dart index dc5154da..fdb11936 100644 --- a/lib/src/result/question/boolean_question_result.g.dart +++ b/lib/src/result/question/boolean_question_result.g.dart @@ -27,7 +27,7 @@ Map _$BooleanQuestionResultToJson( }; const _$BooleanResultEnumMap = { - BooleanResult.NONE: 'NONE', - BooleanResult.POSITIVE: 'POSITIVE', - BooleanResult.NEGATIVE: 'NEGATIVE', + BooleanResult.none: 'none', + BooleanResult.positive: 'positive', + BooleanResult.negative: 'negative', }; diff --git a/lib/src/result/question/date_question_result.dart b/lib/src/result/question/date_question_result.dart index 6f9e2fef..2b0f0f26 100644 --- a/lib/src/result/question/date_question_result.dart +++ b/lib/src/result/question/date_question_result.dart @@ -7,19 +7,13 @@ part 'date_question_result.g.dart'; @JsonSerializable(explicitToJson: true) class DateQuestionResult extends QuestionResult { - DateQuestionResult({ - required Identifier id, - required DateTime startDate, - required DateTime endDate, - required String valueIdentifier, - required DateTime? result, - }) : super( - id: id, - startDate: startDate, - endDate: endDate, - valueIdentifier: valueIdentifier, - result: result, - ); + const DateQuestionResult({ + required Identifier super.id, + required super.startDate, + required super.endDate, + required String super.valueIdentifier, + required super.result, + }); factory DateQuestionResult.fromJson(Map json) => _$DateQuestionResultFromJson(json); diff --git a/lib/src/result/question/double_question_result.dart b/lib/src/result/question/double_question_result.dart index c63b1e79..c06bf087 100644 --- a/lib/src/result/question/double_question_result.dart +++ b/lib/src/result/question/double_question_result.dart @@ -7,19 +7,13 @@ part 'double_question_result.g.dart'; @JsonSerializable(explicitToJson: true) class DoubleQuestionResult extends QuestionResult { - DoubleQuestionResult({ - required Identifier id, - required DateTime startDate, - required DateTime endDate, - required String valueIdentifier, - required double? result, - }) : super( - id: id, - startDate: startDate, - endDate: endDate, - valueIdentifier: valueIdentifier, - result: result, - ); + const DoubleQuestionResult({ + required Identifier super.id, + required super.startDate, + required super.endDate, + required String super.valueIdentifier, + required super.result, + }); factory DoubleQuestionResult.fromJson(Map json) => _$DoubleQuestionResultFromJson(json); diff --git a/lib/src/result/question/image_question_result.dart b/lib/src/result/question/image_question_result.dart index 9e8fdb36..161a92a3 100644 --- a/lib/src/result/question/image_question_result.dart +++ b/lib/src/result/question/image_question_result.dart @@ -6,19 +6,13 @@ part 'image_question_result.g.dart'; @JsonSerializable(explicitToJson: true) class ImageQuestionResult extends QuestionResult { - ImageQuestionResult({ - required Identifier id, - required DateTime startDate, - required DateTime endDate, - required String valueIdentifier, - required String? result, - }) : super( - id: id, - startDate: startDate, - endDate: endDate, - valueIdentifier: valueIdentifier, - result: result, - ); + const ImageQuestionResult({ + required Identifier super.id, + required super.startDate, + required super.endDate, + required String super.valueIdentifier, + required super.result, + }); factory ImageQuestionResult.fromJson(Map json) => _$ImageQuestionResultFromJson(json); diff --git a/lib/src/result/question/integer_question_result.dart b/lib/src/result/question/integer_question_result.dart index b6b858f9..92247f21 100644 --- a/lib/src/result/question/integer_question_result.dart +++ b/lib/src/result/question/integer_question_result.dart @@ -7,19 +7,13 @@ part 'integer_question_result.g.dart'; @JsonSerializable(explicitToJson: true) class IntegerQuestionResult extends QuestionResult { - IntegerQuestionResult({ - required Identifier id, - required DateTime startDate, - required DateTime endDate, - required String valueIdentifier, - required int? result, - }) : super( - id: id, - startDate: startDate, - endDate: endDate, - valueIdentifier: valueIdentifier, - result: result, - ); + const IntegerQuestionResult({ + required Identifier super.id, + required super.startDate, + required super.endDate, + required String super.valueIdentifier, + required super.result, + }); factory IntegerQuestionResult.fromJson(Map json) => _$IntegerQuestionResultFromJson(json); diff --git a/lib/src/result/question/integer_question_result.g.dart b/lib/src/result/question/integer_question_result.g.dart index 10ce54e8..c9d1009d 100644 --- a/lib/src/result/question/integer_question_result.g.dart +++ b/lib/src/result/question/integer_question_result.g.dart @@ -13,7 +13,7 @@ IntegerQuestionResult _$IntegerQuestionResultFromJson( startDate: DateTime.parse(json['startDate'] as String), endDate: DateTime.parse(json['endDate'] as String), valueIdentifier: json['valueIdentifier'] as String, - result: json['result'] as int?, + result: (json['result'] as num?)?.toInt(), ); Map _$IntegerQuestionResultToJson( diff --git a/lib/src/result/question/multiple_choice_question_result.dart b/lib/src/result/question/multiple_choice_question_result.dart index 79762405..3edf0617 100644 --- a/lib/src/result/question/multiple_choice_question_result.dart +++ b/lib/src/result/question/multiple_choice_question_result.dart @@ -8,19 +8,13 @@ part 'multiple_choice_question_result.g.dart'; @JsonSerializable(explicitToJson: true) class MultipleChoiceQuestionResult extends QuestionResult?> { - MultipleChoiceQuestionResult({ - required Identifier id, - required DateTime startDate, - required DateTime endDate, - required String valueIdentifier, - required List? result, - }) : super( - id: id, - startDate: startDate, - endDate: endDate, - valueIdentifier: valueIdentifier, - result: result, - ); + const MultipleChoiceQuestionResult({ + required Identifier super.id, + required super.startDate, + required super.endDate, + required String super.valueIdentifier, + required super.result, + }); factory MultipleChoiceQuestionResult.fromJson(Map json) => _$MultipleChoiceQuestionResultFromJson(json); diff --git a/lib/src/result/question/multiple_double_question_result.dart b/lib/src/result/question/multiple_double_question_result.dart index 72ccc8f8..290c91cd 100644 --- a/lib/src/result/question/multiple_double_question_result.dart +++ b/lib/src/result/question/multiple_double_question_result.dart @@ -8,19 +8,13 @@ part 'multiple_double_question_result.g.dart'; @JsonSerializable(explicitToJson: true) class MultipleDoubleQuestionResult extends QuestionResult?> { - MultipleDoubleQuestionResult({ - required Identifier id, - required DateTime startDate, - required DateTime endDate, - required String valueIdentifier, - required List? result, - }) : super( - id: id, - startDate: startDate, - endDate: endDate, - valueIdentifier: valueIdentifier, - result: result, - ); + const MultipleDoubleQuestionResult({ + required Identifier super.id, + required super.startDate, + required super.endDate, + required String super.valueIdentifier, + required super.result, + }); factory MultipleDoubleQuestionResult.fromJson(Map json) => _$MultipleDoubleQuestionResultFromJson(json); diff --git a/lib/src/result/question/scale_question_result.dart b/lib/src/result/question/scale_question_result.dart index ec67a251..da959863 100644 --- a/lib/src/result/question/scale_question_result.dart +++ b/lib/src/result/question/scale_question_result.dart @@ -7,19 +7,13 @@ part 'scale_question_result.g.dart'; @JsonSerializable(explicitToJson: true) class ScaleQuestionResult extends QuestionResult { - ScaleQuestionResult({ - required Identifier id, - required DateTime startDate, - required DateTime endDate, - required String valueIdentifier, - required double? result, - }) : super( - id: id, - startDate: startDate, - endDate: endDate, - valueIdentifier: valueIdentifier, - result: result, - ); + const ScaleQuestionResult({ + required Identifier super.id, + required super.startDate, + required super.endDate, + required String super.valueIdentifier, + required super.result, + }); factory ScaleQuestionResult.fromJson(Map json) => _$ScaleQuestionResultFromJson(json); diff --git a/lib/src/result/question/single_choice_question_result.dart b/lib/src/result/question/single_choice_question_result.dart index 9c8386b1..c52ce35e 100644 --- a/lib/src/result/question/single_choice_question_result.dart +++ b/lib/src/result/question/single_choice_question_result.dart @@ -8,19 +8,13 @@ part 'single_choice_question_result.g.dart'; @JsonSerializable(explicitToJson: true) class SingleChoiceQuestionResult extends QuestionResult { - SingleChoiceQuestionResult({ - required Identifier id, - required DateTime startDate, - required DateTime endDate, - required String valueIdentifier, - required TextChoice? result, - }) : super( - id: id, - startDate: startDate, - endDate: endDate, - valueIdentifier: valueIdentifier, - result: result, - ); + const SingleChoiceQuestionResult({ + required Identifier super.id, + required super.startDate, + required super.endDate, + required String super.valueIdentifier, + required super.result, + }); factory SingleChoiceQuestionResult.fromJson(Map json) => _$SingleChoiceQuestionResultFromJson(json); diff --git a/lib/src/result/question/text_question_result.dart b/lib/src/result/question/text_question_result.dart index 59cea508..894b7da1 100644 --- a/lib/src/result/question/text_question_result.dart +++ b/lib/src/result/question/text_question_result.dart @@ -7,19 +7,13 @@ part 'text_question_result.g.dart'; @JsonSerializable(explicitToJson: true) class TextQuestionResult extends QuestionResult { - TextQuestionResult({ - required Identifier id, - required DateTime startDate, - required DateTime endDate, - required String valueIdentifier, - required String? result, - }) : super( - id: id, - startDate: startDate, - endDate: endDate, - valueIdentifier: valueIdentifier, - result: result, - ); + const TextQuestionResult({ + required Identifier super.id, + required super.startDate, + required super.endDate, + required String super.valueIdentifier, + required super.result, + }); factory TextQuestionResult.fromJson(Map json) => _$TextQuestionResultFromJson(json); diff --git a/lib/src/result/question/time_question_result.dart b/lib/src/result/question/time_question_result.dart index 71a0cbdd..8e28788b 100644 --- a/lib/src/result/question/time_question_result.dart +++ b/lib/src/result/question/time_question_result.dart @@ -9,19 +9,13 @@ part 'time_question_result.g.dart'; @JsonSerializable(explicitToJson: true) @TimeOfDayConverter() class TimeQuestionResult extends QuestionResult { - TimeQuestionResult({ - required Identifier id, - required DateTime startDate, - required DateTime endDate, - required String valueIdentifier, - required TimeOfDay? result, - }) : super( - id: id, - startDate: startDate, - endDate: endDate, - valueIdentifier: valueIdentifier, - result: result, - ); + const TimeQuestionResult({ + required Identifier super.id, + required super.startDate, + required super.endDate, + required String super.valueIdentifier, + required super.result, + }); factory TimeQuestionResult.fromJson(Map json) => _$TimeQuestionResultFromJson(json); @@ -41,7 +35,7 @@ class TimeOfDayConverter extends JsonConverter { return null; } - String _removeLeadingZeroIfNeeded(String value) { + String removeLeadingZeroIfNeeded(String value) { if (value.startsWith('0')) { const indexOfSecondCharacter = 1; return value.substring(indexOfSecondCharacter); @@ -51,8 +45,8 @@ class TimeOfDayConverter extends JsonConverter { } final elements = json.split(':'); - final hourString = _removeLeadingZeroIfNeeded(elements.first); - final minuteString = _removeLeadingZeroIfNeeded(elements.last); + final hourString = removeLeadingZeroIfNeeded(elements.first); + final minuteString = removeLeadingZeroIfNeeded(elements.last); final hour = int.tryParse(hourString); final minute = int.tryParse(minuteString); @@ -70,14 +64,15 @@ class TimeOfDayConverter extends JsonConverter { return null; } - String _addLeadingZeroIfNeeded(int value) { - if (value < 10) + String addLeadingZeroIfNeeded(int value) { + if (value < 10) { return '0$value'; + } return value.toString(); } - final String hourLabel = _addLeadingZeroIfNeeded(object.hour); - final String minuteLabel = _addLeadingZeroIfNeeded(object.minute); + final String hourLabel = addLeadingZeroIfNeeded(object.hour); + final String minuteLabel = addLeadingZeroIfNeeded(object.minute); return '$hourLabel:$minuteLabel'; } diff --git a/lib/src/result/question_result.dart b/lib/src/result/question_result.dart index bef898cf..092e3ec2 100644 --- a/lib/src/result/question_result.dart +++ b/lib/src/result/question_result.dart @@ -1,14 +1,13 @@ import 'package:survey_kit/src/result/result.dart'; -import 'package:survey_kit/src/steps/identifier/identifier.dart'; abstract class QuestionResult extends Result { final T? result; final String? valueIdentifier; - QuestionResult({ - required Identifier? id, - required DateTime startDate, - required DateTime endDate, + const QuestionResult({ + required super.id, + required super.startDate, + required super.endDate, required this.valueIdentifier, required this.result, - }) : super(id: id, startDate: startDate, endDate: endDate); + }); } diff --git a/lib/src/result/result.dart b/lib/src/result/result.dart index ca0fc1c8..7949f1b3 100644 --- a/lib/src/result/result.dart +++ b/lib/src/result/result.dart @@ -6,7 +6,7 @@ abstract class Result extends Equatable { final DateTime startDate; final DateTime endDate; - Result({ + const Result({ required this.id, required this.startDate, required this.endDate, diff --git a/lib/src/result/step/completion_step_result.dart b/lib/src/result/step/completion_step_result.dart index 62d603ea..e8ba5179 100644 --- a/lib/src/result/step/completion_step_result.dart +++ b/lib/src/result/step/completion_step_result.dart @@ -7,7 +7,7 @@ part 'completion_step_result.g.dart'; @JsonSerializable(explicitToJson: true) class CompletionStepResult extends QuestionResult { - CompletionStepResult( + const CompletionStepResult( Identifier id, DateTime startDate, DateTime endDate, diff --git a/lib/src/result/step/instruction_step_result.dart b/lib/src/result/step/instruction_step_result.dart index 9b82e03b..e3124505 100644 --- a/lib/src/result/step/instruction_step_result.dart +++ b/lib/src/result/step/instruction_step_result.dart @@ -7,7 +7,7 @@ part 'instruction_step_result.g.dart'; @JsonSerializable(explicitToJson: true) class InstructionStepResult extends QuestionResult { - InstructionStepResult( + const InstructionStepResult( Identifier id, DateTime startDate, DateTime endDate, diff --git a/lib/src/result/step/video_step_result.dart b/lib/src/result/step/video_step_result.dart index d6f72fba..9e2b645a 100644 --- a/lib/src/result/step/video_step_result.dart +++ b/lib/src/result/step/video_step_result.dart @@ -8,16 +8,12 @@ part 'video_step_result.g.dart'; @JsonSerializable(explicitToJson: true) class VideoStepResult extends QuestionResult { VideoStepResult({ - required Identifier id, - required DateTime startDate, - required DateTime endDate, - required VideoResult result, + required Identifier super.id, + required super.startDate, + required super.endDate, + required VideoResult super.result, }) : super( - id: id, - startDate: startDate, - endDate: endDate, valueIdentifier: id.id, - result: result, ); factory VideoStepResult.fromJson(Map json) => _$VideoStepResultFromJson(json); diff --git a/lib/src/result/step/video_step_result.g.dart b/lib/src/result/step/video_step_result.g.dart index 7b2e5662..9abc9e82 100644 --- a/lib/src/result/step/video_step_result.g.dart +++ b/lib/src/result/step/video_step_result.g.dart @@ -23,7 +23,7 @@ Map _$VideoStepResultToJson(VideoStepResult instance) => }; VideoResult _$VideoResultFromJson(Map json) => VideoResult( - leftVideoAt: Duration(microseconds: json['leftVideoAt'] as int), + leftVideoAt: Duration(microseconds: (json['leftVideoAt'] as num).toInt()), stayedInVideo: DateTime.parse(json['stayedInVideo'] as String), ); diff --git a/lib/src/result/step_result.dart b/lib/src/result/step_result.dart index 539e75ca..99e8bb10 100644 --- a/lib/src/result/step_result.dart +++ b/lib/src/result/step_result.dart @@ -25,12 +25,11 @@ class StepResult extends Result { @_Converter() final List results; - StepResult( - {required Identifier? id, - required DateTime startDate, - required DateTime endDate, - required this.results}) - : super(id: id, startDate: startDate, endDate: endDate); + const StepResult( + {required super.id, + required super.startDate, + required super.endDate, + required this.results}); factory StepResult.fromQuestion({required QuestionResult questionResult}) { return StepResult( diff --git a/lib/src/result/survey/survey_result.dart b/lib/src/result/survey/survey_result.dart index ef0b5367..3d251312 100644 --- a/lib/src/result/survey/survey_result.dart +++ b/lib/src/result/survey/survey_result.dart @@ -1,9 +1,8 @@ +import 'package:json_annotation/json_annotation.dart'; import 'package:survey_kit/src/result/result.dart'; import 'package:survey_kit/src/result/step_result.dart'; import 'package:survey_kit/src/steps/identifier/identifier.dart'; -import 'package:json_annotation/json_annotation.dart'; - part 'survey_result.g.dart'; @JsonSerializable(explicitToJson: true) @@ -11,15 +10,16 @@ class SurveyResult extends Result { final FinishReason finishReason; final List results; - SurveyResult({ - required Identifier? id, - required DateTime startDate, - required DateTime endDate, + const SurveyResult({ + required super.id, + required super.startDate, + required super.endDate, required this.finishReason, required this.results, - }) : super(id: id, startDate: startDate, endDate: endDate); - - factory SurveyResult.fromJson(Map json) => _$SurveyResultFromJson(json); + }); + + factory SurveyResult.fromJson(Map json) => + _$SurveyResultFromJson(json); Map toJson() => _$SurveyResultToJson(this); @@ -27,4 +27,4 @@ class SurveyResult extends Result { List get props => [id, startDate, endDate, finishReason]; } -enum FinishReason { SAVED, DISCARDED, COMPLETED, FAILED } +enum FinishReason { saved, discarded, completed, failed } diff --git a/lib/src/result/survey/survey_result.g.dart b/lib/src/result/survey/survey_result.g.dart index 09e23f2b..6a9890a3 100644 --- a/lib/src/result/survey/survey_result.g.dart +++ b/lib/src/result/survey/survey_result.g.dart @@ -28,8 +28,8 @@ Map _$SurveyResultToJson(SurveyResult instance) => }; const _$FinishReasonEnumMap = { - FinishReason.SAVED: 'SAVED', - FinishReason.DISCARDED: 'DISCARDED', - FinishReason.COMPLETED: 'COMPLETED', - FinishReason.FAILED: 'FAILED', + FinishReason.saved: 'saved', + FinishReason.discarded: 'discarded', + FinishReason.completed: 'completed', + FinishReason.failed: 'failed', }; diff --git a/lib/src/steps/identifier/identifier.dart b/lib/src/steps/identifier/identifier.dart index d58f23ea..627cca9d 100644 --- a/lib/src/steps/identifier/identifier.dart +++ b/lib/src/steps/identifier/identifier.dart @@ -13,6 +13,8 @@ class Identifier { _$IdentifierFromJson(json); Map toJson() => _$IdentifierToJson(this); - bool operator ==(o) => o is Identifier && o.id == id; + @override + bool operator ==(other) => other is Identifier && other.id == id; + @override int get hashCode => id.hashCode; } diff --git a/lib/src/steps/identifier/step_identifier.dart b/lib/src/steps/identifier/step_identifier.dart index 94a6636b..a0fa6b17 100644 --- a/lib/src/steps/identifier/step_identifier.dart +++ b/lib/src/steps/identifier/step_identifier.dart @@ -5,12 +5,15 @@ part 'step_identifier.g.dart'; @JsonSerializable() class StepIdentifier extends Identifier { - StepIdentifier({String? id}) : super(id: id); + StepIdentifier({super.id}); factory StepIdentifier.fromJson(Map json) => _$StepIdentifierFromJson(json); + @override Map toJson() => _$StepIdentifierToJson(this); - bool operator ==(o) => o is StepIdentifier && id == o.id; + @override + bool operator ==(other) => other is StepIdentifier && id == other.id; + @override int get hashCode => id.hashCode; } diff --git a/lib/src/steps/predefined_steps/completion_step.dart b/lib/src/steps/predefined_steps/completion_step.dart index 735b24ba..fa9a396a 100644 --- a/lib/src/steps/predefined_steps/completion_step.dart +++ b/lib/src/steps/predefined_steps/completion_step.dart @@ -1,8 +1,8 @@ import 'package:flutter/widgets.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:survey_kit/src/result/question_result.dart'; -import 'package:survey_kit/src/steps/step.dart'; import 'package:survey_kit/src/steps/identifier/step_identifier.dart'; +import 'package:survey_kit/src/steps/step.dart'; import 'package:survey_kit/src/views/completion_view.dart'; part 'completion_step.g.dart'; @@ -13,20 +13,14 @@ class CompletionStep extends Step { final String text; final String assetPath; - CompletionStep({ - bool isOptional = false, - required StepIdentifier stepIdentifier, - String buttonText = 'End Survey', - bool showAppBar = true, - required this.title, - required this.text, - this.assetPath = "" - }) : super( - stepIdentifier: stepIdentifier, - isOptional: isOptional, - buttonText: buttonText, - showAppBar: showAppBar, - ); + CompletionStep( + {super.isOptional, + required StepIdentifier super.stepIdentifier, + String super.buttonText = 'End Survey', + super.showAppBar, + required this.title, + required this.text, + this.assetPath = ""}); @override Widget createView({required QuestionResult? questionResult}) { @@ -35,9 +29,15 @@ class CompletionStep extends Step { factory CompletionStep.fromJson(Map json) => _$CompletionStepFromJson(json); + @override Map toJson() => _$CompletionStepToJson(this); - bool operator ==(o) => - super == (o) && o is CompletionStep && o.title == title && o.text == text; + @override + bool operator ==(other) => + super == (other) && + other is CompletionStep && + other.title == title && + other.text == text; + @override int get hashCode => super.hashCode ^ title.hashCode ^ text.hashCode; } diff --git a/lib/src/steps/predefined_steps/instruction_step.dart b/lib/src/steps/predefined_steps/instruction_step.dart index d767cfe0..1133056f 100644 --- a/lib/src/steps/predefined_steps/instruction_step.dart +++ b/lib/src/steps/predefined_steps/instruction_step.dart @@ -1,8 +1,8 @@ import 'package:flutter/widgets.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:survey_kit/src/result/question_result.dart'; -import 'package:survey_kit/src/steps/step.dart'; import 'package:survey_kit/src/steps/identifier/step_identifier.dart'; +import 'package:survey_kit/src/steps/step.dart'; import 'package:survey_kit/src/views/instruction_view.dart'; part 'instruction_step.g.dart'; @@ -15,19 +15,15 @@ class InstructionStep extends Step { InstructionStep({ required this.title, required this.text, - bool isOptional = false, - String buttonText = 'Next', - StepIdentifier? stepIdentifier, + super.isOptional, + String super.buttonText, + super.stepIdentifier, bool? canGoBack, bool? showProgress, - bool showAppBar = true, + super.showAppBar, }) : super( - stepIdentifier: stepIdentifier, - isOptional: isOptional, - buttonText: buttonText, canGoBack: canGoBack ?? false, showProgress: showProgress ?? false, - showAppBar: showAppBar, ); @override @@ -39,12 +35,15 @@ class InstructionStep extends Step { factory InstructionStep.fromJson(Map json) => _$InstructionStepFromJson(json); + @override Map toJson() => _$InstructionStepToJson(this); - bool operator ==(o) => - super == (o) && - o is InstructionStep && - o.title == title && - o.text == text; + @override + bool operator ==(other) => + super == (other) && + other is InstructionStep && + other.title == title && + other.text == text; + @override int get hashCode => super.hashCode ^ title.hashCode ^ text.hashCode; } diff --git a/lib/src/steps/predefined_steps/question_step.dart b/lib/src/steps/predefined_steps/question_step.dart index 06d96494..2f171c3d 100644 --- a/lib/src/steps/predefined_steps/question_step.dart +++ b/lib/src/steps/predefined_steps/question_step.dart @@ -57,24 +57,19 @@ class QuestionStep extends Step { final AnswerFormat answerFormat; QuestionStep({ - bool isOptional = false, - String buttonText = 'Next', - StepIdentifier? stepIdentifier, - bool showAppBar = true, + super.isOptional, + String super.buttonText, + super.stepIdentifier, + super.showAppBar, this.title = '', this.text = '', this.content = const SizedBox.shrink(), required this.answerFormat, - }) : super( - stepIdentifier: stepIdentifier, - isOptional: isOptional, - buttonText: buttonText, - showAppBar: showAppBar, - ); + }); @override Widget createView({required QuestionResult? questionResult}) { - final key = ObjectKey(this.stepIdentifier.id); + final key = ObjectKey(stepIdentifier.id); switch (answerFormat.runtimeType) { case IntegerAnswerFormat: @@ -163,5 +158,6 @@ class QuestionStep extends Step { factory QuestionStep.fromJson(Map json) => _$QuestionStepFromJson(json); + @override Map toJson() => _$QuestionStepToJson(this); } diff --git a/lib/src/steps/step.dart b/lib/src/steps/step.dart index 1b3dbceb..9623a43e 100644 --- a/lib/src/steps/step.dart +++ b/lib/src/steps/step.dart @@ -42,11 +42,13 @@ abstract class Step { Map toJson(); - bool operator ==(o) => - o is Step && - o.stepIdentifier == stepIdentifier && - o.isOptional == isOptional && - o.buttonText == buttonText; + @override + bool operator ==(other) => + other is Step && + other.stepIdentifier == stepIdentifier && + other.isOptional == isOptional && + other.buttonText == buttonText; + @override int get hashCode => stepIdentifier.hashCode ^ isOptional.hashCode ^ buttonText.hashCode; } diff --git a/lib/src/survey_kit.dart b/lib/src/survey_kit.dart index 5dbaf0b3..dc5cfd3a 100644 --- a/lib/src/survey_kit.dart +++ b/lib/src/survey_kit.dart @@ -42,6 +42,7 @@ class SurveyKit extends StatefulWidget { final Map? localizations; const SurveyKit({ + super.key, required this.task, required this.onResult, this.themeData, @@ -53,7 +54,7 @@ class SurveyKit extends StatefulWidget { }); @override - _SurveyKitState createState() => _SurveyKitState(); + State createState() => _SurveyKitState(); } class _SurveyKitState extends State { @@ -119,13 +120,14 @@ class SurveyPage extends StatefulWidget { final Function(SurveyResult) onResult; const SurveyPage({ + super.key, required this.length, required this.onResult, this.appBar, }); @override - _SurveyPageState createState() => _SurveyPageState(); + State createState() => _SurveyPageState(); } class _SurveyPageState extends State diff --git a/lib/src/task/identifier/task_identifier.dart b/lib/src/task/identifier/task_identifier.dart index 6c8d2591..1d14ae10 100644 --- a/lib/src/task/identifier/task_identifier.dart +++ b/lib/src/task/identifier/task_identifier.dart @@ -6,9 +6,10 @@ part 'task_identifier.g.dart'; /// Used to uniquly identify a [Task] @JsonSerializable() class TaskIdentifier extends Identifier { - TaskIdentifier({String? id}) : super(id: id); + TaskIdentifier({super.id}); factory TaskIdentifier.fromJson(Map json) => _$TaskIdentifierFromJson(json); + @override Map toJson() => _$TaskIdentifierToJson(this); } diff --git a/lib/src/task/navigable_task.dart b/lib/src/task/navigable_task.dart index 40ba3bc4..9e9b5ece 100644 --- a/lib/src/task/navigable_task.dart +++ b/lib/src/task/navigable_task.dart @@ -13,14 +13,12 @@ class NavigableTask extends Task { final Map navigationRules; NavigableTask({ - TaskIdentifier? id, - List steps = const [], + super.id, + super.steps, Step? initialStep, Map? navigationRules, - }) : this.navigationRules = navigationRules ?? {}, + }) : navigationRules = navigationRules ?? {}, super( - id: id, - steps: steps, initalStep: initialStep, ); @@ -62,6 +60,7 @@ class NavigableTask extends Task { ); } + @override Map toJson() => { 'id': id.toJson(), 'steps': steps.map((step) => step.toJson()).toList(), diff --git a/lib/src/task/ordered_task.dart b/lib/src/task/ordered_task.dart index e35b7d34..13b11240 100644 --- a/lib/src/task/ordered_task.dart +++ b/lib/src/task/ordered_task.dart @@ -9,12 +9,10 @@ part 'ordered_task.g.dart'; @JsonSerializable(createFactory: false) class OrderedTask extends Task { OrderedTask({ - required TaskIdentifier id, - required List steps, + required TaskIdentifier super.id, + required super.steps, Step? initialStep, }) : super( - id: id, - steps: steps, initalStep: initialStep, ); @@ -27,5 +25,6 @@ class OrderedTask extends Task { : [], ); + @override Map toJson() => _$OrderedTaskToJson(this); } diff --git a/lib/src/task/task.dart b/lib/src/task/task.dart index 248e3b2e..93af0cfd 100644 --- a/lib/src/task/task.dart +++ b/lib/src/task/task.dart @@ -21,11 +21,7 @@ abstract class Task { this.steps = const [], this.initalStep, }) { - if (id == null) { - id = TaskIdentifier(); - return; - } - this.id = id; + this.id = id ?? TaskIdentifier(); } /// Creates a task from a Map. The task needs to have a type definition of @@ -43,6 +39,8 @@ abstract class Task { Map toJson(); - bool operator ==(o) => o is Task && o.id == id; + @override + bool operator ==(other) => other is Task && other.id == id; + @override int get hashCode => id.hashCode ^ steps.hashCode; } diff --git a/lib/src/views/agreement_answer_view.dart b/lib/src/views/agreement_answer_view.dart index 4fb8a942..3dd20638 100644 --- a/lib/src/views/agreement_answer_view.dart +++ b/lib/src/views/agreement_answer_view.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; -import 'package:survey_kit/src/answer_format/boolean_answer_format.dart'; import 'package:survey_kit/src/answer_format/agreement_answer_format.dart'; +import 'package:survey_kit/src/answer_format/boolean_answer_format.dart'; import 'package:survey_kit/src/result/question/agreement_question_result.dart'; import 'package:survey_kit/src/steps/predefined_steps/question_step.dart'; import 'package:survey_kit/src/views/widget/step_view.dart'; @@ -12,13 +12,13 @@ class AgreementAnswerView extends StatefulWidget { final AgreementQuestionResult? result; const AgreementAnswerView({ - Key? key, + super.key, required this.questionStep, required this.result, - }) : super(key: key); + }); @override - _AgreementAnswerViewState createState() => _AgreementAnswerViewState(); + State createState() => _AgreementAnswerViewState(); } class _AgreementAnswerViewState extends State { @@ -33,7 +33,7 @@ class _AgreementAnswerViewState extends State { widget.questionStep.answerFormat as AgreementAnswerFormat; _result = widget.result?.result ?? _agreementAnswerFormat.defaultValue ?? - BooleanResult.NEGATIVE; + BooleanResult.negative; _startDate = DateTime.now(); } @@ -52,7 +52,7 @@ class _AgreementAnswerViewState extends State { result: _result, ), isValid: widget.questionStep.isOptional || - (_result != null && _result == BooleanResult.POSITIVE), + (_result != null && _result == BooleanResult.positive), title: widget.questionStep.title.isNotEmpty ? Text( widget.questionStep.title, @@ -91,7 +91,7 @@ class _AgreementAnswerViewState extends State { children: [ Radio( groupValue: _result, - value: BooleanResult.POSITIVE, + value: BooleanResult.positive, onChanged: (v) { setState(() { _result = v; @@ -104,10 +104,10 @@ class _AgreementAnswerViewState extends State { child: GestureDetector( onTap: () { setState(() { - if (_result == BooleanResult.POSITIVE) { - _result = BooleanResult.NEGATIVE; + if (_result == BooleanResult.positive) { + _result = BooleanResult.negative; } else { - _result = BooleanResult.POSITIVE; + _result = BooleanResult.positive; } }); }, diff --git a/lib/src/views/boolean_answer_view.dart b/lib/src/views/boolean_answer_view.dart index 2fe290db..5b887f4c 100644 --- a/lib/src/views/boolean_answer_view.dart +++ b/lib/src/views/boolean_answer_view.dart @@ -10,13 +10,13 @@ class BooleanAnswerView extends StatefulWidget { final BooleanQuestionResult? result; const BooleanAnswerView({ - Key? key, + super.key, required this.questionStep, required this.result, - }) : super(key: key); + }); @override - _BooleanAnswerViewState createState() => _BooleanAnswerViewState(); + State createState() => _BooleanAnswerViewState(); } class _BooleanAnswerViewState extends State { @@ -42,9 +42,9 @@ class _BooleanAnswerViewState extends State { id: widget.questionStep.stepIdentifier, startDate: _startDate, endDate: DateTime.now(), - valueIdentifier: _result == BooleanResult.POSITIVE + valueIdentifier: _result == BooleanResult.positive ? _answerFormat.positiveAnswer - : _result == BooleanResult.NEGATIVE + : _result == BooleanResult.negative ? _answerFormat.negativeAnswer : '', result: _result, @@ -57,7 +57,7 @@ class _BooleanAnswerViewState extends State { ) : widget.questionStep.content, isValid: widget.questionStep.isOptional || - (_result != BooleanResult.NONE && _result != null), + (_result != BooleanResult.none && _result != null), child: Column( children: [ Padding( @@ -76,26 +76,26 @@ class _BooleanAnswerViewState extends State { SelectionListTile( text: _answerFormat.positiveAnswer, onTap: () { - if (_result == BooleanResult.POSITIVE) { + if (_result == BooleanResult.positive) { _result = null; } else { - _result = BooleanResult.POSITIVE; + _result = BooleanResult.positive; } setState(() {}); }, - isSelected: _result == BooleanResult.POSITIVE, + isSelected: _result == BooleanResult.positive, ), SelectionListTile( text: _answerFormat.negativeAnswer, onTap: () { - if (_result == BooleanResult.NEGATIVE) { + if (_result == BooleanResult.negative) { _result = null; } else { - _result = BooleanResult.NEGATIVE; + _result = BooleanResult.negative; } setState(() {}); }, - isSelected: _result == BooleanResult.NEGATIVE, + isSelected: _result == BooleanResult.negative, ), ], ), diff --git a/lib/src/views/completion_view.dart b/lib/src/views/completion_view.dart index 976eb89e..9db6d56d 100644 --- a/lib/src/views/completion_view.dart +++ b/lib/src/views/completion_view.dart @@ -9,7 +9,7 @@ class CompletionView extends StatelessWidget { final DateTime _startDate = DateTime.now(); final String assetPath; - CompletionView({required this.completionStep, this.assetPath = ""}); + CompletionView({super.key, required this.completionStep, this.assetPath = ""}); @override Widget build(BuildContext context) { @@ -34,7 +34,7 @@ class CompletionView extends StatelessWidget { ), Padding( padding: const EdgeInsets.symmetric(vertical: 32.0), - child: Container( + child: SizedBox( width: 150.0, height: 150.0, child: assetPath.isNotEmpty diff --git a/lib/src/views/date_answer_view.dart b/lib/src/views/date_answer_view.dart index af95bcd7..88c7ec51 100644 --- a/lib/src/views/date_answer_view.dart +++ b/lib/src/views/date_answer_view.dart @@ -15,13 +15,13 @@ class DateAnswerView extends StatefulWidget { final DateQuestionResult? result; const DateAnswerView({ - Key? key, + super.key, required this.questionStep, required this.result, - }) : super(key: key); + }); @override - _DateAnswerViewState createState() => _DateAnswerViewState(); + State createState() => _DateAnswerViewState(); } class _DateAnswerViewState extends State { @@ -108,7 +108,7 @@ class _DateAnswerViewState extends State { ], ), ), - Container( + SizedBox( width: double.infinity, height: 300.0, child: CalendarDatePicker( @@ -129,7 +129,7 @@ class _DateAnswerViewState extends State { } Widget _iosDatePicker() { - return Container( + return SizedBox( width: double.infinity, height: 400.0, child: CupertinoDatePicker( diff --git a/lib/src/views/double_answer_view.dart b/lib/src/views/double_answer_view.dart index 05651836..dd2a4771 100644 --- a/lib/src/views/double_answer_view.dart +++ b/lib/src/views/double_answer_view.dart @@ -10,13 +10,13 @@ class DoubleAnswerView extends StatefulWidget { final DoubleQuestionResult? result; const DoubleAnswerView({ - Key? key, + super.key, required this.questionStep, required this.result, - }) : super(key: key); + }); @override - _DoubleAnswerViewState createState() => _DoubleAnswerViewState(); + State createState() => _DoubleAnswerViewState(); } class _DoubleAnswerViewState extends State { @@ -59,8 +59,7 @@ class _DoubleAnswerViewState extends State { endDate: DateTime.now(), valueIdentifier: _controller.text, result: double.tryParse(_controller.text) ?? - _doubleAnswerFormat.defaultValue ?? - null, + _doubleAnswerFormat.defaultValue, ), isValid: _isValid || widget.questionStep.isOptional, title: widget.questionStep.title.isNotEmpty @@ -72,7 +71,7 @@ class _DoubleAnswerViewState extends State { : widget.questionStep.content, child: Padding( padding: const EdgeInsets.symmetric(vertical: 32.0), - child: Container( + child: SizedBox( width: MediaQuery.of(context).size.width, child: TextField( autofocus: true, diff --git a/lib/src/views/image_answer_view.dart b/lib/src/views/image_answer_view.dart index 80be0809..b215ce7d 100644 --- a/lib/src/views/image_answer_view.dart +++ b/lib/src/views/image_answer_view.dart @@ -10,10 +10,10 @@ class ImageAnswerView extends StatefulWidget { final ImageQuestionResult? result; const ImageAnswerView({ - Key? key, + super.key, required this.questionStep, required this.result, - }) : super(key: key); + }); @override State createState() => _ImageAnswerViewState(); @@ -23,7 +23,7 @@ class _ImageAnswerViewState extends State { late final ImageAnswerFormat _imageAnswerFormat; late final DateTime _startDate; - bool _isValid = false; + final bool _isValid = false; String filePath = ''; @override @@ -59,7 +59,7 @@ class _ImageAnswerViewState extends State { : widget.questionStep.content, child: Padding( padding: const EdgeInsets.symmetric(vertical: 32.0), - child: Container( + child: SizedBox( width: MediaQuery.of(context).size.width, child: Column( children: [ @@ -155,12 +155,11 @@ class _ImageAnswerViewState extends State { } Future _openCamera() async { - Container(); - var picture = await ImagePicker().pickImage( source: ImageSource.camera, ); + if (!mounted) return; Navigator.pop(context); picture?.readAsBytes().then((value) { @@ -175,6 +174,7 @@ class _ImageAnswerViewState extends State { source: ImageSource.gallery, ); + if (!mounted) return; Navigator.pop(context); picture?.readAsBytes().then((value) { diff --git a/lib/src/views/instruction_view.dart b/lib/src/views/instruction_view.dart index acdc499c..01a6a2d5 100644 --- a/lib/src/views/instruction_view.dart +++ b/lib/src/views/instruction_view.dart @@ -7,7 +7,7 @@ class InstructionView extends StatelessWidget { final InstructionStep instructionStep; final DateTime _startDate = DateTime.now(); - InstructionView({required this.instructionStep}); + InstructionView({super.key, required this.instructionStep}); @override Widget build(BuildContext context) { diff --git a/lib/src/views/integer_answer_view.dart b/lib/src/views/integer_answer_view.dart index d8aa599c..96a3461a 100644 --- a/lib/src/views/integer_answer_view.dart +++ b/lib/src/views/integer_answer_view.dart @@ -10,13 +10,13 @@ class IntegerAnswerView extends StatefulWidget { final IntegerQuestionResult? result; const IntegerAnswerView({ - Key? key, + super.key, required this.questionStep, required this.result, - }) : super(key: key); + }); @override - _IntegerAnswerViewState createState() => _IntegerAnswerViewState(); + State createState() => _IntegerAnswerViewState(); } class _IntegerAnswerViewState extends State { @@ -58,9 +58,8 @@ class _IntegerAnswerViewState extends State { startDate: _startDate, endDate: DateTime.now(), valueIdentifier: _controller.text, - result: int.tryParse(_controller.text) ?? - _integerAnswerFormat.defaultValue ?? - null, + result: + int.tryParse(_controller.text) ?? _integerAnswerFormat.defaultValue, ), isValid: _isValid || widget.questionStep.isOptional, title: widget.questionStep.title.isNotEmpty @@ -72,7 +71,7 @@ class _IntegerAnswerViewState extends State { : widget.questionStep.content, child: Padding( padding: const EdgeInsets.symmetric(vertical: 32.0), - child: Container( + child: SizedBox( width: MediaQuery.of(context).size.width, child: TextField( textInputAction: TextInputAction.next, diff --git a/lib/src/views/multiple_auto_complete_answer_view.dart b/lib/src/views/multiple_auto_complete_answer_view.dart index 5a10e57a..c0f0ea1c 100644 --- a/lib/src/views/multiple_auto_complete_answer_view.dart +++ b/lib/src/views/multiple_auto_complete_answer_view.dart @@ -8,10 +8,10 @@ class MultipleChoiceAutoCompleteAnswerView extends StatefulWidget { final QuestionStep questionStep; final MultipleChoiceQuestionResult? result; const MultipleChoiceAutoCompleteAnswerView({ - Key? key, + super.key, required this.questionStep, this.result, - }) : super(key: key); + }); @override State createState() => @@ -88,7 +88,7 @@ class _MultipleChoiceAutoCompleteAnswerViewState isSelected: _selectedChoices.contains(tc), ), ) - .toList(), + , ..._selectedChoices .where((element) => !_multipleChoiceAnswer.textChoices.contains(element)) @@ -99,7 +99,7 @@ class _MultipleChoiceAutoCompleteAnswerViewState isSelected: _selectedChoices.contains(tc), ), ) - .toList(), + , if (_multipleChoiceAnswer.otherField) ...[ Padding( padding: const EdgeInsets.symmetric(horizontal: 14.0), @@ -169,11 +169,10 @@ class _MultipleChoiceAutoCompleteAnswerViewState class _AutoComplete extends StatelessWidget { const _AutoComplete({ - Key? key, required this.suggestions, required this.onSelected, required this.selectedChoices, - }) : super(key: key); + }); final List suggestions; final void Function(TextChoice) onSelected; @@ -224,11 +223,10 @@ class _AutoComplete extends StatelessWidget { class _OptionsViewBuilder extends StatelessWidget { const _OptionsViewBuilder({ - Key? key, required this.options, required this.onSelected, required this.selectedChoices, - }) : super(key: key); + }); final Iterable options; final void Function(TextChoice) onSelected; diff --git a/lib/src/views/multiple_choice_answer_view.dart b/lib/src/views/multiple_choice_answer_view.dart index 01a95515..4e8570e2 100644 --- a/lib/src/views/multiple_choice_answer_view.dart +++ b/lib/src/views/multiple_choice_answer_view.dart @@ -12,13 +12,13 @@ class MultipleChoiceAnswerView extends StatefulWidget { final MultipleChoiceQuestionResult? result; const MultipleChoiceAnswerView({ - Key? key, + super.key, required this.questionStep, required this.result, - }) : super(key: key); + }); @override - _MultipleChoiceAnswerView createState() => _MultipleChoiceAnswerView(); + State createState() => _MultipleChoiceAnswerView(); } class _MultipleChoiceAnswerView extends State { @@ -74,28 +74,26 @@ class _MultipleChoiceAnswerView extends State { Divider( color: Colors.grey, ), - ..._multipleChoiceAnswer.textChoices - .map( - (TextChoice tc) => SelectionListTile( - text: tc.text, - onTap: () { - setState( - () { - if (_selectedChoices.contains(tc)) { - _selectedChoices.remove(tc); - } else { - if (_multipleChoiceAnswer.maxAnswers > - _selectedChoices.length) { - _selectedChoices = [..._selectedChoices, tc]; - } - } - }, - ); + ..._multipleChoiceAnswer.textChoices.map( + (TextChoice tc) => SelectionListTile( + text: tc.text, + onTap: () { + setState( + () { + if (_selectedChoices.contains(tc)) { + _selectedChoices.remove(tc); + } else { + if (_multipleChoiceAnswer.maxAnswers > + _selectedChoices.length) { + _selectedChoices = [..._selectedChoices, tc]; + } + } }, - isSelected: _selectedChoices.contains(tc), - ), - ) - .toList(), + ); + }, + isSelected: _selectedChoices.contains(tc), + ), + ), if (_multipleChoiceAnswer.otherField) ...[ Padding( padding: const EdgeInsets.symmetric(horizontal: 14.0), diff --git a/lib/src/views/multiple_double_answer_view.dart b/lib/src/views/multiple_double_answer_view.dart index ad7dc7eb..53547b6b 100644 --- a/lib/src/views/multiple_double_answer_view.dart +++ b/lib/src/views/multiple_double_answer_view.dart @@ -10,10 +10,10 @@ class MultipleDoubleAnswerView extends StatefulWidget { final MultipleDoubleQuestionResult? result; const MultipleDoubleAnswerView({ - Key? key, + super.key, required this.questionStep, required this.result, - }) : super(key: key); + }); @override State createState() => @@ -127,7 +127,7 @@ class _MultipleDoubleAnswerViewState extends State { keyboardType: TextInputType.number, textAlign: TextAlign.center, ); - }).toList(), + }), ], ) ], diff --git a/lib/src/views/scale_answer_view.dart b/lib/src/views/scale_answer_view.dart index 701b94da..6157999b 100644 --- a/lib/src/views/scale_answer_view.dart +++ b/lib/src/views/scale_answer_view.dart @@ -9,13 +9,13 @@ class ScaleAnswerView extends StatefulWidget { final ScaleQuestionResult? result; const ScaleAnswerView({ - Key? key, + super.key, required this.questionStep, required this.result, - }) : super(key: key); + }); @override - _ScaleAnswerViewState createState() => _ScaleAnswerViewState(); + State createState() => _ScaleAnswerViewState(); } class _ScaleAnswerViewState extends State { diff --git a/lib/src/views/single_choice_answer_view.dart b/lib/src/views/single_choice_answer_view.dart index 6d279f77..f9e37aef 100644 --- a/lib/src/views/single_choice_answer_view.dart +++ b/lib/src/views/single_choice_answer_view.dart @@ -11,13 +11,13 @@ class SingleChoiceAnswerView extends StatefulWidget { final SingleChoiceQuestionResult? result; const SingleChoiceAnswerView({ - Key? key, + super.key, required this.questionStep, required this.result, - }) : super(key: key); + }); @override - _SingleChoiceAnswerViewState createState() => _SingleChoiceAnswerViewState(); + State createState() => _SingleChoiceAnswerViewState(); } class _SingleChoiceAnswerViewState extends State { @@ -86,7 +86,7 @@ class _SingleChoiceAnswerViewState extends State { isSelected: _selectedChoice == tc, ); }, - ).toList(), + ), ], ), ], diff --git a/lib/src/views/text_answer_view.dart b/lib/src/views/text_answer_view.dart index fb8c6dbf..7aa6c587 100644 --- a/lib/src/views/text_answer_view.dart +++ b/lib/src/views/text_answer_view.dart @@ -10,13 +10,13 @@ class TextAnswerView extends StatefulWidget { final TextQuestionResult? result; const TextAnswerView({ - Key? key, + super.key, required this.questionStep, required this.result, - }) : super(key: key); + }); @override - _TextAnswerViewState createState() => _TextAnswerViewState(); + State createState() => _TextAnswerViewState(); } class _TextAnswerViewState extends State { @@ -40,7 +40,7 @@ class _TextAnswerViewState extends State { void _checkValidation(String text) { setState(() { if (_textAnswerFormat.validationRegEx != null) { - RegExp regExp = new RegExp(_textAnswerFormat.validationRegEx!); + RegExp regExp = RegExp(_textAnswerFormat.validationRegEx!); _isValid = regExp.hasMatch(text); } else { _isValid = true; @@ -84,7 +84,7 @@ class _TextAnswerViewState extends State { textAlign: TextAlign.center, ), ), - Container( + SizedBox( width: MediaQuery.of(context).size.width, height: 50.0, child: TextField( diff --git a/lib/src/views/time_answer_view.dart b/lib/src/views/time_answer_view.dart index f6391621..5081cec4 100644 --- a/lib/src/views/time_answer_view.dart +++ b/lib/src/views/time_answer_view.dart @@ -13,13 +13,13 @@ class TimeAnswerView extends StatefulWidget { final TimeQuestionResult? result; const TimeAnswerView({ - Key? key, + super.key, required this.questionStep, required this.result, - }) : super(key: key); + }); @override - _TimeAnswerViewState createState() => _TimeAnswerViewState(); + State createState() => _TimeAnswerViewState(); } class _TimeAnswerViewState extends State { @@ -77,7 +77,7 @@ class _TimeAnswerViewState extends State { } Widget _androidTimePicker() { - return Container( + return SizedBox( width: double.infinity, height: 450.0, child: surveywidget.TimePickerWidget( @@ -95,7 +95,7 @@ class _TimeAnswerViewState extends State { } Widget _iosTimePicker() { - return Container( + return SizedBox( width: double.infinity, height: 450.0, child: CupertinoDatePicker( diff --git a/lib/src/views/widget/selection_list_tile.dart b/lib/src/views/widget/selection_list_tile.dart index de52b05e..cadbc2b1 100644 --- a/lib/src/views/widget/selection_list_tile.dart +++ b/lib/src/views/widget/selection_list_tile.dart @@ -6,11 +6,11 @@ class SelectionListTile extends StatelessWidget { final bool isSelected; const SelectionListTile({ - Key? key, + super.key, required this.text, required this.onTap, this.isSelected = false, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -35,7 +35,7 @@ class SelectionListTile extends StatelessWidget { ? Theme.of(context).primaryColor : Colors.black, ) - : Container( + : SizedBox( width: 32, height: 32, ), diff --git a/lib/src/views/widget/step_view.dart b/lib/src/views/widget/step_view.dart index 9b5c40e7..690e7c4d 100644 --- a/lib/src/views/widget/step_view.dart +++ b/lib/src/views/widget/step_view.dart @@ -12,7 +12,7 @@ class StepView extends StatelessWidget { final bool isValid; final SurveyController? controller; - const StepView({ + const StepView({super.key, required this.step, required this.child, required this.title, @@ -23,9 +23,9 @@ class StepView extends StatelessWidget { @override Widget build(BuildContext context) { - final _surveyController = controller ?? context.read(); + final surveyController = controller ?? context.read(); - return _content(_surveyController, context); + return _content(surveyController, context); } Widget _content(SurveyController surveyController, BuildContext context) { diff --git a/lib/src/views/widget/survey_app_bar.dart b/lib/src/views/widget/survey_app_bar.dart index 9c35bf9a..3ccbf8e4 100644 --- a/lib/src/views/widget/survey_app_bar.dart +++ b/lib/src/views/widget/survey_app_bar.dart @@ -8,21 +8,21 @@ class SurveyAppBar extends StatelessWidget { final AppBarConfiguration appBarConfiguration; final SurveyController? controller; - const SurveyAppBar({ + const SurveyAppBar({super.key, required this.appBarConfiguration, this.controller, }); @override AppBar build(BuildContext context) { - final _showProgress = + final showProgress = appBarConfiguration.showProgress ?? context.read(); - final _canGoBack = appBarConfiguration.canBack ?? true; + final canGoBack = appBarConfiguration.canBack ?? true; final surveyController = controller ?? context.read(); return AppBar( elevation: 0, - leading: _canGoBack + leading: canGoBack ? appBarConfiguration.leading ?? BackButton( onPressed: () { @@ -32,7 +32,7 @@ class SurveyAppBar extends StatelessWidget { }, ) : Container(), - title: _showProgress ? SurveyProgress() : SizedBox.shrink(), + title: showProgress ? SurveyProgress() : SizedBox.shrink(), actions: [ if (appBarConfiguration.showCancelButton ?? true) TextButton( diff --git a/lib/src/views/widget/time_picker_widget.dart b/lib/src/views/widget/time_picker_widget.dart index 296d36db..45cc77e8 100644 --- a/lib/src/views/widget/time_picker_widget.dart +++ b/lib/src/views/widget/time_picker_widget.dart @@ -680,11 +680,10 @@ class _DayPeriodControl extends StatelessWidget { /// A widget to pad the area around the [_DayPeriodControl]'s inner [Material]. class _DayPeriodInputPadding extends SingleChildRenderObjectWidget { const _DayPeriodInputPadding({ - Key? key, - required Widget child, + required Widget super.child, required this.minSize, required this.orientation, - }) : super(key: key, child: child); + }); final Size minSize; final Orientation orientation; @@ -1236,7 +1235,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { ]; List<_TappableLabel> _buildMinutes(TextTheme textTheme, Color color) { - const List _minuteMarkerValues = [ + const List minuteMarkerValues = [ TimeOfDay(hour: 0, minute: 0), TimeOfDay(hour: 0, minute: 5), TimeOfDay(hour: 0, minute: 10), @@ -1252,7 +1251,7 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { ]; return <_TappableLabel>[ - for (final TimeOfDay timeOfDay in _minuteMarkerValues) + for (final TimeOfDay timeOfDay in minuteMarkerValues) _buildTappableLabel( textTheme, color, @@ -1328,13 +1327,12 @@ class _DialState extends State<_Dial> with SingleTickerProviderStateMixin { class _TimePickerInput extends StatefulWidget { const _TimePickerInput({ - Key? key, required this.initialSelectedTime, required this.helpText, required this.autofocusHour, required this.autofocusMinute, required this.onChanged, - }) : super(key: key); + }); /// The time initially selected when the dialog is shown. final TimeOfDay initialSelectedTime; @@ -1590,14 +1588,13 @@ class _TimePickerInputState extends State<_TimePickerInput> { class _HourTextField extends StatelessWidget { const _HourTextField({ - Key? key, required this.selectedTime, required this.style, required this.autofocus, required this.validator, required this.onSavedSubmitted, required this.onChanged, - }) : super(key: key); + }); final TimeOfDay selectedTime; final TextStyle style; @@ -1623,13 +1620,12 @@ class _HourTextField extends StatelessWidget { class _MinuteTextField extends StatelessWidget { const _MinuteTextField({ - Key? key, required this.selectedTime, required this.style, required this.autofocus, required this.validator, required this.onSavedSubmitted, - }) : super(key: key); + }); final TimeOfDay selectedTime; final TextStyle style; @@ -1653,7 +1649,6 @@ class _MinuteTextField extends StatelessWidget { class _HourMinuteTextField extends StatefulWidget { const _HourMinuteTextField({ - Key? key, required this.selectedTime, required this.isHour, required this.autofocus, @@ -1662,7 +1657,7 @@ class _HourMinuteTextField extends StatefulWidget { required this.validator, required this.onSavedSubmitted, this.onChanged, - }) : super(key: key); + }); final TimeOfDay selectedTime; final bool isHour; @@ -1804,14 +1799,14 @@ class TimePickerWidget extends StatefulWidget { /// /// [initialTime] must not be null. const TimePickerWidget({ - Key? key, + super.key, required this.initialTime, required this.timeChanged, this.cancelText = '', this.confirmText = '', this.helpText = '', this.initialEntryMode = TimePickerEntryMode.dial, - }) : super(key: key); + }); final Function(TimeOfDay time) timeChanged; @@ -1835,7 +1830,7 @@ class TimePickerWidget extends StatefulWidget { final String? helpText; @override - _TimePickerWidgetState createState() => _TimePickerWidgetState(); + State createState() => _TimePickerWidgetState(); } class _TimePickerWidgetState extends State { diff --git a/lib/src/widget/survey_progress.dart b/lib/src/widget/survey_progress.dart index c3829cc9..ce11df46 100644 --- a/lib/src/widget/survey_progress.dart +++ b/lib/src/widget/survey_progress.dart @@ -5,7 +5,7 @@ import 'package:survey_kit/src/presenter/survey_state.dart'; import 'package:survey_kit/src/widget/survey_progress_configuration.dart'; class SurveyProgress extends StatefulWidget { - const SurveyProgress({Key? key}) : super(key: key); + const SurveyProgress({super.key}); @override State createState() => _SurveyProgressState(); diff --git a/pubspec.lock b/pubspec.lock index d57a42b2..984c2cf3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -336,6 +336,14 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1" + url: "https://pub.dev" + source: hosted + version: "5.0.0" flutter_markdown: dependency: "direct main" description: @@ -564,6 +572,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.1" + lints: + dependency: transitive + description: + name: lints + sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413" + url: "https://pub.dev" + source: hosted + version: "5.0.0" logging: dependency: transitive description: @@ -957,10 +973,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc url: "https://pub.dev" source: hosted - version: "14.2.5" + version: "14.2.4" watcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index f657d23d..5e9b8e62 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -36,38 +36,8 @@ dev_dependencies: json_serializable: ^6.1.3 integration_test: sdk: flutter + flutter_lints: ^5.0.0 -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter. flutter: - # To add assets to your plugin package, add an assets section, like this: assets: - assets/fancy_checkmark.json - # - # For details regarding assets in packages, see - # https://flutter.dev/assets-and-images/#from-packages - # - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware. - - # To add custom fonts to your plugin package, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts in packages, see - # https://flutter.dev/custom-fonts/#from-packages diff --git a/test/src/result/question/boolean_question_result_test.dart b/test/src/result/question/boolean_question_result_test.dart index bd403083..0b66ad12 100644 --- a/test/src/result/question/boolean_question_result_test.dart +++ b/test/src/result/question/boolean_question_result_test.dart @@ -7,7 +7,7 @@ void main() { startDate: DateTime(2022, 8, 12, 16, 4), endDate: DateTime(2022, 8, 12, 16, 14), valueIdentifier: 'bool1', - result: BooleanResult.NEGATIVE, + result: BooleanResult.negative, ); group('serialisation', () { diff --git a/test/src/survey/survey_result_test.dart b/test/src/survey/survey_result_test.dart index 9119994e..05209eee 100644 --- a/test/src/survey/survey_result_test.dart +++ b/test/src/survey/survey_result_test.dart @@ -13,7 +13,7 @@ void main() { startDate: DateTime(2022, 8, 12, 16, 5), endDate: DateTime(2022, 8, 12, 16, 10), valueIdentifier: 'bool1', - result: BooleanResult.NEGATIVE, + result: BooleanResult.negative, ), CompletionStepResult( Identifier(id: 'example1_completion'), @@ -25,7 +25,7 @@ void main() { id: Identifier(id: 'example1'), startDate: DateTime(2022, 8, 12, 16, 4), endDate: DateTime(2022, 8, 12, 16, 14), - finishReason: FinishReason.COMPLETED, + finishReason: FinishReason.completed, results: [ StepResult( id: Identifier(id: 'example1_stepResult'), diff --git a/test/surveykit_flutter_test.dart b/test/surveykit_flutter_test.dart index 6151cebb..a3f745d6 100644 --- a/test/surveykit_flutter_test.dart +++ b/test/surveykit_flutter_test.dart @@ -32,7 +32,7 @@ void main() { ], ), onResult: (result) { - expect(result.finishReason, FinishReason.COMPLETED); + expect(result.finishReason, FinishReason.completed); }, ), ), diff --git a/test/views/date_answer_view_test.dart b/test/views/date_answer_view_test.dart index 92b4206b..e085faa9 100644 --- a/test/views/date_answer_view_test.dart +++ b/test/views/date_answer_view_test.dart @@ -10,7 +10,7 @@ import 'package:survey_kit/src/views/date_answer_view.dart'; import 'package:survey_kit/src/widget/survey_progress_configuration.dart'; void main() { - DateAnswerView _validDateAnswerView() => DateAnswerView( + DateAnswerView validDateAnswerView() => DateAnswerView( questionStep: QuestionStep( answerFormat: DateAnswerFormat( minDate: DateTime.now().subtract(const Duration(days: 365 * 70)), @@ -37,7 +37,7 @@ void main() { value: SurveyProgressConfiguration(), ), ], - child: _validDateAnswerView(), + child: validDateAnswerView(), ), ), ); @@ -62,7 +62,7 @@ void main() { value: SurveyProgressConfiguration(), ), ], - child: _validDateAnswerView(), + child: validDateAnswerView(), ), ), ),