diff --git a/admin/lib/presentation/app/localization/l10n/app_en.arb b/admin/lib/presentation/app/localization/l10n/app_en.arb index ae8c41ea..a02f3650 100644 --- a/admin/lib/presentation/app/localization/l10n/app_en.arb +++ b/admin/lib/presentation/app/localization/l10n/app_en.arb @@ -23,7 +23,6 @@ "emptyDataMessage": "Data has not been loaded", "emptyQuestionMessage": "Data cannot be exported", "emptySubtitle":"", - "end": "End", "enterText": "Enter text", "export": "EXPORT", "exportFloatingWindowTitle": "Save generated json-file with all settings to use in your app", @@ -41,7 +40,6 @@ "input": "Input", "inputHintText": "Enter answer here", "inputType": "Input type", - "intro": "Intro", "lines": "Lines", "max": "max", "min": "min", diff --git a/admin/lib/presentation/pages/builder/builder_cubit.dart b/admin/lib/presentation/pages/builder/builder_cubit.dart index bb68e951..3f1110dc 100644 --- a/admin/lib/presentation/pages/builder/builder_cubit.dart +++ b/admin/lib/presentation/pages/builder/builder_cubit.dart @@ -41,8 +41,8 @@ class BuilderCubit extends Cubit { } void select(QuestionData data) { - if (state is EditQuestionBuilderState || - state is ImportSuccessSurveyDataBuilderState) { + if (state is EditQuestionBuilderState || + state is ImportSuccessSurveyDataBuilderState) { emit( EditQuestionBuilderState( selectedIndex: data.index, @@ -65,13 +65,7 @@ class BuilderCubit extends Cubit { _updateIndex(questionList); - final endPage = state.surveyData.endPage - .copyWith(index: state.surveyData.endPage.index - 1); - - final surveyData = state.surveyData.copyWith( - questions: questionList, - endPage: endPage, - ); + final surveyData = state.surveyData.copyWith(questions: questionList); _sessionStorageRepository.saveSurveyData(surveyData); emit(state.copyWith(surveyData: surveyData)); if (state.surveyData.questions.isEmpty) { @@ -90,13 +84,7 @@ class BuilderCubit extends Cubit { final questionList = List.of(state.surveyData.questions) ..add(data); - final endPage = state.surveyData.endPage - .copyWith(index: state.surveyData.endPage.index + 1); - - final surveyData = state.surveyData.copyWith( - questions: questionList, - endPage: endPage, - ); + final surveyData = state.surveyData.copyWith(questions: questionList); _sessionStorageRepository.saveSurveyData(surveyData); emit(state.copyWith(surveyData: surveyData)); select(state.surveyData.questions.last); diff --git a/admin/lib/presentation/pages/builder/builder_page.dart b/admin/lib/presentation/pages/builder/builder_page.dart index b9e682a1..e345b3b2 100644 --- a/admin/lib/presentation/pages/builder/builder_page.dart +++ b/admin/lib/presentation/pages/builder/builder_page.dart @@ -50,11 +50,8 @@ class _ContentState extends State<_Content> final cubit = this.cubit(context); final questions = cubit.state.surveyData.questions; final index = _surveyController.pageController.page; - final question = index == questions.length - ? cubit.state.surveyData.endPage - : index != null && index % 1 == 0 - ? questions[index.toInt()] - : null; + final question = + index != null && index % 1 == 0 ? questions[index.toInt()] : null; if (question != null) { cubit.select(question); @@ -87,10 +84,8 @@ class _ContentState extends State<_Content> QuestionData? _editableQuestion(BuilderState state) { if (state is EditQuestionBuilderState) { - return state.selectedIndex == state.surveyData.endPage.index - ? state.surveyData.endPage - : state.surveyData.questions - .firstWhereOrNull((q) => q.index == state.selectedIndex); + return state.surveyData.questions + .firstWhereOrNull((q) => q.index == state.selectedIndex); } else if (state is PreviewQuestionBuilderState) { return state.selectedQuestion; } else { @@ -164,7 +159,6 @@ class _ContentState extends State<_Content> data: cubit.state.surveyData, onUpdate: cubit.updateQuestions, selectedIndex: _selectedIndex(state), - endPage: state.surveyData.endPage, onDataUpdate: cubit.updateCommonTheme, ), Expanded( diff --git a/admin/lib/presentation/utils/common_data.dart b/admin/lib/presentation/utils/common_data.dart index c4d4772b..47a00c25 100644 --- a/admin/lib/presentation/utils/common_data.dart +++ b/admin/lib/presentation/utils/common_data.dart @@ -11,7 +11,6 @@ class CommonData { static const _secondIndex = 2; static const _thirdIndex = 3; static const _fourthIndex = 4; - static const _fifthIndex = 5; static const _dividers = 10; CommonTheme get commonTheme { @@ -26,22 +25,21 @@ class CommonData { SurveyData get surveyData { return SurveyData( questions: [ - info(index: _firstIndex, title: context.localization.intro), + info(index: _firstIndex), input(index: _secondIndex), choice(index: _thirdIndex), slider(index: _fourthIndex), ], - endPage: endPage(index: _fifthIndex), commonTheme: commonTheme, ); } const CommonData(this.context); - InfoQuestionData info({int index = 0, String? title}) { + InfoQuestionData info({int index = 0}) { return InfoQuestionData( primaryButtonText: context.localization.next, - title: title ?? context.localization.info, + title: context.localization.info, index: index, subtitle: context.localization.emptySubtitle, isSkip: false, @@ -111,19 +109,4 @@ class CommonData { secondaryButtonAction: const SkipQuestionAction(), ); } - - InfoQuestionData endPage({int index = 0}) { - return InfoQuestionData( - primaryButtonText: context.localization.next, - title: context.localization.end, - index: index, - subtitle: context.localization.surveyCompleted, - isSkip: false, - content: context.localization.emptyContent, - theme: const InfoQuestionTheme.common(), - secondaryButtonText: context.localization.skip, - mainButtonAction: const GoNextAction(), - secondaryButtonAction: const SkipQuestionAction(), - ); - } } diff --git a/admin/lib/presentation/widgets/builder_page/question_list.dart b/admin/lib/presentation/widgets/builder_page/question_list.dart index 49ed84c7..b3a48fdc 100644 --- a/admin/lib/presentation/widgets/builder_page/question_list.dart +++ b/admin/lib/presentation/widgets/builder_page/question_list.dart @@ -15,14 +15,12 @@ class QuestionList extends StatefulWidget { final int? selectedIndex; final SurveyData data; final ValueChanged onDataUpdate; - final InfoQuestionData endPage; final bool isEditMode; const QuestionList({ required this.onSelect, required this.onAdd, required this.data, - required this.endPage, required this.onUpdate, required this.onDelete, required this.onDataUpdate, @@ -103,13 +101,6 @@ class _QuestionListState extends State { question: widget.data.questions[index], onQuestionTap: widget.onSelect, ), - _Question( - key: ValueKey(length), - index: length, - isSelected: length == widget.selectedIndex, - question: widget.endPage, - onQuestionTap: widget.onSelect, - ), ], ), cardBuilder: (_, children) { diff --git a/admin/test/presentation/pages/builder/buider_test.dart b/admin/test/presentation/pages/builder/buider_test.dart index 302b18b9..b55a1b37 100644 --- a/admin/test/presentation/pages/builder/buider_test.dart +++ b/admin/test/presentation/pages/builder/buider_test.dart @@ -44,7 +44,7 @@ void main() { expect(find.text('Survey'), findsOneWidget); expect(find.text('Common'), findsOneWidget); expect(find.text('Content'), findsOneWidget); - expect(find.text('Intro'), findsNWidgets(3)); + expect(find.text('Info'), findsNWidgets(3)); expect(find.text('Input'), findsOneWidget); expect(find.text('Choice'), findsOneWidget); expect(find.text('NEXT'), findsNWidgets(2)); @@ -132,11 +132,11 @@ void main() { await tester.pumpWidget(page); - await tester.longPress(find.text('Intro').first); + await tester.longPress(find.text('Info').first); await tester.tap(find.text('Delete')); await tester.pumpAndSettle(); - expect(find.text('Intro'), findsNothing); + expect(find.text('Info'), findsNothing); tester.binding.platformDispatcher.clearTextScaleFactorTestValue(); }); diff --git a/admin/test/utils/shared_mocks.mocks.dart b/admin/test/utils/shared_mocks.mocks.dart index 0f37a8d5..82671740 100644 --- a/admin/test/utils/shared_mocks.mocks.dart +++ b/admin/test/utils/shared_mocks.mocks.dart @@ -27,9 +27,8 @@ import 'package:survey_sdk/survey_sdk.dart' as _i2; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeInfoQuestionData_0 extends _i1.SmartFake - implements _i2.InfoQuestionData { - _FakeInfoQuestionData_0( +class _FakeCommonTheme_0 extends _i1.SmartFake implements _i2.CommonTheme { + _FakeCommonTheme_0( Object parent, Invocation parentInvocation, ) : super( @@ -38,18 +37,8 @@ class _FakeInfoQuestionData_0 extends _i1.SmartFake ); } -class _FakeCommonTheme_1 extends _i1.SmartFake implements _i2.CommonTheme { - _FakeCommonTheme_1( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakeSurveyData_2 extends _i1.SmartFake implements _i2.SurveyData { - _FakeSurveyData_2( +class _FakeSurveyData_1 extends _i1.SmartFake implements _i2.SurveyData { + _FakeSurveyData_1( Object parent, Invocation parentInvocation, ) : super( @@ -166,17 +155,9 @@ class MockSurveyData extends _i1.Mock implements _i2.SurveyData { returnValue: <_i2.QuestionData>[], ) as List<_i2.QuestionData>); @override - _i2.InfoQuestionData get endPage => (super.noSuchMethod( - Invocation.getter(#endPage), - returnValue: _FakeInfoQuestionData_0( - this, - Invocation.getter(#endPage), - ), - ) as _i2.InfoQuestionData); - @override _i2.CommonTheme get commonTheme => (super.noSuchMethod( Invocation.getter(#commonTheme), - returnValue: _FakeCommonTheme_1( + returnValue: _FakeCommonTheme_0( this, Invocation.getter(#commonTheme), ), @@ -189,7 +170,6 @@ class MockSurveyData extends _i1.Mock implements _i2.SurveyData { @override _i2.SurveyData copyWith({ List<_i2.QuestionData>? questions, - _i2.InfoQuestionData? endPage, _i2.CommonTheme? commonTheme, }) => (super.noSuchMethod( @@ -198,18 +178,16 @@ class MockSurveyData extends _i1.Mock implements _i2.SurveyData { [], { #questions: questions, - #endPage: endPage, #commonTheme: commonTheme, }, ), - returnValue: _FakeSurveyData_2( + returnValue: _FakeSurveyData_1( this, Invocation.method( #copyWith, [], { #questions: questions, - #endPage: endPage, #commonTheme: commonTheme, }, ), diff --git a/core/example/assets/questions.json b/core/example/assets/questions.json index fcddeab3..7a5548fe 100644 --- a/core/example/assets/questions.json +++ b/core/example/assets/questions.json @@ -1,36 +1,5 @@ { "schemeVersion": 1, - "endPage": { - "index": 5, - "title": "End", - "subtitle": "Survey is completed", - "type": "Info", - "isSkip": false, - "content": "", - "theme": { - "fill": 4294967295, - "titleColor": 4278190080, - "titleSize": 16, - "subtitleColor": 4278190080, - "subtitleSize": 12, - "primaryButtonFill": 4278190080, - "primaryButtonTextColor": 4294967295, - "primaryButtonTextSize": 12, - "primaryButtonRadius": 10, - "secondaryButtonFill": 4278190080, - "secondaryButtonTextColor": 4294967295, - "secondaryButtonTextSize": 12, - "secondaryButtonRadius": 10 - }, - "secondaryButtonText": "Skip", - "primaryButtonText": "NEXT", - "primaryButtonAction": { - "type": "GoNext" - }, - "secondaryButtonAction": { - "type": "SkipQuestion" - } - }, "commonTheme": { "slider": { "index": 0, @@ -201,42 +170,11 @@ "questions": [ { "index": 1, - "title": "Intro", + "title": "Info", "subtitle": "", "type": "Info", "isSkip": false, "content": "You may simply need a single, brief answer without discussion. Other times, you may want to talk through a scenario, evaluate how well a group is learning new material or solicit feedback. The types of questions you ask directly impact the type of answer you receive.", - "theme": { - "fill": 4294967295, - "titleColor": 4278190080, - "titleSize": 16, - "subtitleColor": 4278190080, - "subtitleSize": 12, - "primaryButtonFill": 4278190080, - "primaryButtonTextColor": 4294967295, - "primaryButtonTextSize": 12, - "primaryButtonRadius": 10, - "secondaryButtonFill": 4278190080, - "secondaryButtonTextColor": 4294967295, - "secondaryButtonTextSize": 12, - "secondaryButtonRadius": 10 - }, - "secondaryButtonText": "Skip", - "primaryButtonText": "NEXT", - "primaryButtonAction": { - "type": "GoNext" - }, - "secondaryButtonAction": { - "type": "SkipQuestion" - } - }, - { - "index": 2, - "title": "Input", - "subtitle": "", - "type": "Input", - "isSkip": false, - "content": "You may simply need a single, brief answer without discussion. Other times, you may want to talk through a scenario, evaluate how well a group is learning new material or solicit feedback. The types of questions you ask directly impact the type of answer you receive.", "theme": { "inputFill": 4294967295, "borderColor": 4278190080, diff --git a/core/lib/src/domain/entities/survey_data.dart b/core/lib/src/domain/entities/survey_data.dart index 67c67878..37591c18 100644 --- a/core/lib/src/domain/entities/survey_data.dart +++ b/core/lib/src/domain/entities/survey_data.dart @@ -10,7 +10,6 @@ import 'package:survey_sdk/survey_sdk.dart'; abstract class _Fields { static const String questions = 'questions'; - static const String endPage = 'endPage'; static const String commonTheme = 'commonTheme'; static const String schemeVersion = 'schemeVersion'; } @@ -22,9 +21,6 @@ class SurveyData with EquatableMixin, ApiObject { /// of questions. final List questions; - /// Contains last page in the survey. - final InfoQuestionData endPage; - /// Defines the visual properties used throughout the app. final CommonTheme commonTheme; @@ -36,22 +32,18 @@ class SurveyData with EquatableMixin, ApiObject { SurveyData({ required this.questions, - required this.endPage, required this.commonTheme, }); factory SurveyData.fromJson(Map json) { final questions = []; final schemeVersion = json[_Fields.schemeVersion]; - final endPage = QuestionData.fromType(json[_Fields.endPage], schemeVersion) - as InfoQuestionData; for (final questionJson in json[_Fields.questions]) { questions.add(QuestionData.fromType(questionJson, schemeVersion)); } return SurveyData( questions: questions, - endPage: endPage, commonTheme: CommonTheme.fromJson( json[_Fields.commonTheme], schemeVersion, @@ -61,12 +53,10 @@ class SurveyData with EquatableMixin, ApiObject { SurveyData copyWith({ List? questions, - InfoQuestionData? endPage, CommonTheme? commonTheme, }) { return SurveyData( questions: questions ?? this.questions, - endPage: endPage ?? this.endPage, commonTheme: commonTheme ?? this.commonTheme, ); } @@ -76,11 +66,6 @@ class SurveyData with EquatableMixin, ApiObject { const schemeVersion = SchemeInfo.version; return { _Fields.schemeVersion: schemeVersion, - _Fields.endPage: _toJson( - _themeFromQuestionType(endPage.type), - endPage, - schemeVersion, - ), _Fields.commonTheme: commonTheme.toJson( schemeVersion: schemeVersion, ), diff --git a/core/lib/src/presentation/end_page/end_page.dart b/core/lib/src/presentation/end_page/end_page.dart deleted file mode 100644 index 995880ee..00000000 --- a/core/lib/src/presentation/end_page/end_page.dart +++ /dev/null @@ -1,49 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:survey_sdk/src/domain/entities/question_types/info_question_data.dart'; -import 'package:survey_sdk/src/domain/entities/themes/info_question_theme.dart'; -import 'package:survey_sdk/src/presentation/utils/utils.dart'; -import 'package:survey_sdk/src/presentation/widgets/info_data_view.dart'; - -/// The question page for displaying info content. -/// -/// The [EndPage] widget is used to display information content to -/// the user. It can contain a title, subtitle, and buttons for navigation. -class EndPage extends StatefulWidget { - /// Contains the content for a page. - final InfoQuestionData data; - - const EndPage({ - required this.data, - super.key, - }); - - @override - State createState() => _EndPageState(); -} - -class _EndPageState extends State { - @override - Widget build(BuildContext context) { - final theme = - widget.data.theme ?? Theme.of(context).extension()!; - return Scaffold( - backgroundColor: theme.fill, - body: CustomScrollView( - slivers: [ - SliverFillRemaining( - hasScrollBody: false, - child: Padding( - padding: const EdgeInsets.only( - left: SurveyDimensions.margin2XL, - right: SurveyDimensions.margin2XL, - top: SurveyDimensions.margin3XL, - bottom: SurveyDimensions.marginXL, - ), - child: InfoDataView(data: widget.data), - ), - ), - ], - ), - ); - } -} diff --git a/core/lib/src/presentation/utils/data_to_widget_util.dart b/core/lib/src/presentation/utils/data_to_widget_util.dart index 484c681b..b2eb3ce0 100644 --- a/core/lib/src/presentation/utils/data_to_widget_util.dart +++ b/core/lib/src/presentation/utils/data_to_widget_util.dart @@ -6,7 +6,6 @@ import 'package:survey_sdk/src/domain/entities/question_types/input_question_dat import 'package:survey_sdk/src/domain/entities/question_types/question_data.dart'; import 'package:survey_sdk/src/domain/entities/question_types/slider_question_data.dart'; import 'package:survey_sdk/src/presentation/choice_question/choice_question_page.dart'; -import 'package:survey_sdk/src/presentation/end_page/end_page.dart'; import 'package:survey_sdk/src/presentation/info_question/info_question_page.dart'; import 'package:survey_sdk/src/presentation/input_question/input_question_page.dart'; import 'package:survey_sdk/src/presentation/slider_question/slider_question_page.dart'; @@ -56,7 +55,4 @@ abstract class DataToWidgetUtil { throw Exception('Unimplemented error'); } } - - static Widget createEndPage({required InfoQuestionData data}) => - EndPage(data: data); } diff --git a/core/test/assets/test_survey_data.json b/core/test/assets/test_survey_data.json index a0041f2d..d844b671 100644 --- a/core/test/assets/test_survey_data.json +++ b/core/test/assets/test_survey_data.json @@ -1,34 +1,5 @@ { "schemeVersion": 1, - "endPage": { - "index": 5, - "title": "End", - "subtitle": "Survey is completed", - "type": "Info", - "isSkip": false, - "content": "", - "theme": { - "fill": 4294967295, - "titleColor": 4278190080, - "titleSize": 16, - "subtitleColor": 4278190080, - "subtitleSize": 12, - "primaryButtonFill": 4278190080, - "primaryButtonTextColor": 4294967295, - "primaryButtonTextSize": 12, - "primaryButtonRadius": 10, - "secondaryButtonFill": 4278190080, - "secondaryButtonTextColor": 4294967295, - "secondaryButtonTextSize": 12, - "secondaryButtonRadius": 10 - }, - "secondaryButtonText": "Skip", - "primaryButtonText": "NEXT", - "actions": { - "mainButtonAction": null, - "secondaryButtonAction": null - } - }, "commonTheme": { "slider": { "index": 0, @@ -191,7 +162,7 @@ "questions": [ { "index": 1, - "title": "Intro", + "title": "Info", "subtitle": "", "type": "Info", "isSkip": false, diff --git a/core/test/assets/test_survey_incorrect_data.json b/core/test/assets/test_survey_incorrect_data.json index f2ffaac4..3fcfd49d 100644 --- a/core/test/assets/test_survey_incorrect_data.json +++ b/core/test/assets/test_survey_incorrect_data.json @@ -1,34 +1,5 @@ { "schemeVersion": 1, - "endPage": { - "index": 5, - "title": "End", - "subtitle": "Survey is completed", - "type": "Info", - "isSkip": false, - "content": "", - "theme": { - "fill": 4294967295, - "titleColor": 4278190080, - "titleSize": 16, - "subtitleColor": 4278190080, - "subtitleSize": 12, - "primaryButtonFill": 4278190080, - "primaryButtonTextColor": 4294967295, - "primaryButtonTextSize": 12, - "primaryButtonRadius": 10, - "secondaryButtonFill": 4278190080, - "secondaryButtonTextColor": 4294967295, - "secondaryButtonTextSize": 12, - "secondaryButtonRadius": 10 - }, - "secondaryButtonText": "Skip", - "primaryButtonText": "NEXT", - "actions": { - "mainButtonAction": null, - "secondaryButtonAction": null - } - }, "commonTheme ": { "slider": { "index": 0, @@ -191,7 +162,7 @@ "questions": [ { "index": 1, - "title": "Intro", + "title": "Info", "subtitle": "", "type": "Info", "isSkip": false, diff --git a/core/test/presentation/cubits/survey_cubit_test.dart b/core/test/presentation/cubits/survey_cubit_test.dart index f7cdd569..2acf5143 100644 --- a/core/test/presentation/cubits/survey_cubit_test.dart +++ b/core/test/presentation/cubits/survey_cubit_test.dart @@ -23,7 +23,6 @@ void main() { final currentState = surveyCubit.state; final surveyData = SurveyData( questions: [], - endPage: const InfoQuestionData.common(), commonTheme: CommonTheme( slider: const SliderQuestionData.common(), choice: const ChoiceQuestionData.common(), diff --git a/core/test/utils/mocked_entities.dart b/core/test/utils/mocked_entities.dart index 5e616665..fb977ba7 100644 --- a/core/test/utils/mocked_entities.dart +++ b/core/test/utils/mocked_entities.dart @@ -154,7 +154,7 @@ abstract class MockedEntities { secondaryButtonText: 'EXIT', ); - static const endPage = InfoQuestionData( + static const infoPage1 = InfoQuestionData( primaryButtonText: 'NEXT', title: 'title', index: 0, @@ -170,8 +170,8 @@ abstract class MockedEntities { choice1.copyWith(index: 2), choice2.copyWith(index: 3), slider1.copyWith(index: 4), + infoPage1.copyWith(index: 5), ], - endPage: endPage.copyWith(index: 5), commonTheme: _commonTheme, );