From 7f02dff6894a6562e510280e4c9a724c2c2c2cfc Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Mon, 16 Jan 2023 15:39:57 +0300 Subject: [PATCH] Added the Sequence Number in Question Options and Removed isCorrectOption --- assets/json/demo_questions_marathon | 8 +- lib/api/marathon/demo_marathon_repo.dart | 3 - lib/classes/consts.dart | 2 +- lib/extensions/string_extensions.dart | 9 +++ lib/models/marathon/question_model.dart | 1 + lib/ui/marathon/marathon_provider.dart | 75 ++++++++++++++----- .../marathon_sponsor_video_screen.dart | 14 ++-- .../countdown_timer_detail_screen.dart | 1 + lib/ui/marathon/widgets/marathon_banner.dart | 20 +++-- .../widgets/marathon_details_card.dart | 26 +++++-- .../widgets/marathon_progress_container.dart | 2 +- 11 files changed, 110 insertions(+), 51 deletions(-) diff --git a/assets/json/demo_questions_marathon b/assets/json/demo_questions_marathon index 5e0bc8e..b735fc1 100644 --- a/assets/json/demo_questions_marathon +++ b/assets/json/demo_questions_marathon @@ -27,7 +27,7 @@ "titleEn": "2", "titleAr": "2", "questionId": "b8f10b10-221c-495d-b99b-6a8094892549", - "sequence": 2, + "sequence": 3, "image": "null", "isCorrectOption": true }, @@ -36,7 +36,7 @@ "titleEn": "3", "titleAr": "3", "questionId": "b8f10b10-221c-495d-b99b-6a8094892549", - "sequence": 3, + "sequence": 2, "image": "null", "isCorrectOption": false }, @@ -79,7 +79,7 @@ "titleEn": "Argentina", "titleAr": "Argentina", "questionId": "0d60d55f-4067-48f9-9ace-b6309c6a7cf0", - "sequence": 2, + "sequence": 4, "image": "null", "isCorrectOption": true }, @@ -97,7 +97,7 @@ "titleEn": "France", "titleAr": "France", "questionId": "0d60d55f-4067-48f9-9ace-b6309c6a7cf0", - "sequence": 4, + "sequence": 2, "image": "null", "isCorrectOption": false } diff --git a/lib/api/marathon/demo_marathon_repo.dart b/lib/api/marathon/demo_marathon_repo.dart index a93a146..1e53472 100644 --- a/lib/api/marathon/demo_marathon_repo.dart +++ b/lib/api/marathon/demo_marathon_repo.dart @@ -11,16 +11,13 @@ class DemoMarathonRepo { Future getDemoMarathonDetails() async { String response = await rootBundle.loadString('assets/json/demo_upcoming_marathon'); var json = jsonDecode(response); - logger.i("json in getDemoMarathonDetails: $json"); MarathonDetailModel marathonDetailModel = MarathonDetailModel.fromJson(json); return marathonDetailModel; } Future getDemoNextQuestion({required int currentQuestionNumber}) async { - print("currentNumber: $currentQuestionNumber"); String response = await rootBundle.loadString('assets/json/demo_questions_marathon'); List json = jsonDecode(response); - logger.i("json in getDemoNextQuestion: $json"); QuestionModel currentQuestion = QuestionModel.fromJson(json.elementAt(currentQuestionNumber)); return currentQuestion; diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 6679cbb..56ddde6 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -4,7 +4,7 @@ class ApiConsts { //static String baseUrl = "http://10.200.204.20:2801/"; // Local server // static String baseUrl = "https://erptstapp.srca.org.sa"; // SRCA server static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server - // static String baseUrl = "https://hmgwebservices.com"; // Live server + // static String baseUrl = "https://hmgwebservices.com"; // Live server static String baseUrlServices = baseUrl + "/Services/"; // server // static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/"; diff --git a/lib/extensions/string_extensions.dart b/lib/extensions/string_extensions.dart index 41b8952..b916f23 100644 --- a/lib/extensions/string_extensions.dart +++ b/lib/extensions/string_extensions.dart @@ -13,6 +13,15 @@ extension CapExtension on String { String get capitalizeFirstofEach => this.trim().length > 0 ? this.trim().toLowerCase().split(" ").map((str) => str.inCaps).join(" ") : ""; } +extension TrimString on String { + String trimString(int minThreshold) { + if (length > minThreshold) { + return "${substring(0, 10)}...${substring(length - 4, length)}"; + } + return this; + } +} + extension EmailValidator on String { Widget get toWidget => Text(this); diff --git a/lib/models/marathon/question_model.dart b/lib/models/marathon/question_model.dart index 4501947..d79e42f 100644 --- a/lib/models/marathon/question_model.dart +++ b/lib/models/marathon/question_model.dart @@ -51,6 +51,7 @@ class QuestionModel { json['questionOptions'].forEach((v) { questionOptions!.add(QuestionOptions.fromJson(v)); }); + questionOptions!.sort((QuestionOptions a, QuestionOptions b) => a.sequence!.compareTo(b.sequence!)); } } diff --git a/lib/ui/marathon/marathon_provider.dart b/lib/ui/marathon/marathon_provider.dart index 9781475..9185a19 100644 --- a/lib/ui/marathon/marathon_provider.dart +++ b/lib/ui/marathon/marathon_provider.dart @@ -221,19 +221,19 @@ class MarathonProvider extends ChangeNotifier { getCorrectAnswerAndUpdateAnswerColor(); } - if (totalCurrentQuestionTime == currentGapTime) { + if (totalCurrentQuestionTime - currentGapTime == -2) { updateCardStatusToAnswer(); - scheduleMicrotask(() async { - if (AppState().getIsDemoMarathon || isUserOutOfGame) { - await callNextQuestionApi(); - } else { - await callSubmitOptionApi().then((bool value) async { - updateIsUserOutOfGame = !value; - await callNextQuestionApi(); - }); - } - }); + // scheduleMicrotask(() async { + // if (AppState().getIsDemoMarathon || isUserOutOfGame) { + // await callNextQuestionApi(); + // } else { + // await callSubmitOptionApi().then((bool value) async { + // updateIsUserOutOfGame = !value; + // await callNextQuestionApi(); + // }); + // } + // }); if (currentQuestionNumber == (AppState().getIsDemoMarathon ? demoMarathonDetailModel.totalQuestions! : marathonDetailModel.totalQuestions!)) { isGettingQualifiers = true; @@ -253,7 +253,7 @@ class MarathonProvider extends ChangeNotifier { return; } else { - if (totalCurrentQuestionTime != currentGapTime) { + if (totalCurrentQuestionTime - currentGapTime != -2) { totalCurrentQuestionTime--; } } @@ -414,10 +414,31 @@ class MarathonProvider extends ChangeNotifier { void getCorrectAnswerAndUpdateAnswerColor() { if (selectedOptionIndex != null) { - if (currentQuestion.questionOptions![selectedOptionIndex!].isCorrectOption!) { - updateCurrentQuestionOptionStatus(QuestionsOptionStatus.correct, selectedOptionIndex!); - } else { - updateCurrentQuestionOptionStatus(QuestionsOptionStatus.wrong, selectedOptionIndex!); + scheduleMicrotask(() async { + if (AppState().getIsDemoMarathon) { + if (currentQuestion.questionOptions![selectedOptionIndex!].isCorrectOption!) { + updateCurrentQuestionOptionStatus(QuestionsOptionStatus.correct, selectedOptionIndex!); + } else { + updateCurrentQuestionOptionStatus(QuestionsOptionStatus.wrong, selectedOptionIndex!); + } + } else { + await callSubmitOptionApi().then((bool value) async { + updateIsUserOutOfGame = !value; + if (value) { + updateCurrentQuestionOptionStatus(QuestionsOptionStatus.correct, selectedOptionIndex!); + } else { + updateCurrentQuestionOptionStatus(QuestionsOptionStatus.wrong, selectedOptionIndex!); + } + }); + } + }); + } else { + if (!AppState().getIsDemoMarathon) { + scheduleMicrotask(() async { + await callSubmitOptionApi().then((bool value) async { + updateIsUserOutOfGame = !value; + }); + }); } } } @@ -427,7 +448,16 @@ class MarathonProvider extends ChangeNotifier { return; } - if (selectedOptionIndex != null) { + scheduleMicrotask(() async { + await callNextQuestionApi(); + }); + + if (selectedOptionIndex == null) { + updateQuestionCardStatus(QuestionCardStatus.skippedAnswer); + updateAnswerStatusesList(QuestionCardStatus.skippedAnswer); + return; + } + if (AppState().getIsDemoMarathon) { if (currentQuestion.questionOptions![selectedOptionIndex!].isCorrectOption!) { updateQuestionCardStatus(QuestionCardStatus.correctAnswer); updateAnswerStatusesList(QuestionCardStatus.correctAnswer); @@ -435,10 +465,15 @@ class MarathonProvider extends ChangeNotifier { updateQuestionCardStatus(QuestionCardStatus.wrongAnswer); updateAnswerStatusesList(QuestionCardStatus.wrongAnswer); } - } else { - updateQuestionCardStatus(QuestionCardStatus.skippedAnswer); - updateAnswerStatusesList(QuestionCardStatus.skippedAnswer); + return; + } + if (!isUserOutOfGame) { + updateQuestionCardStatus(QuestionCardStatus.correctAnswer); + updateAnswerStatusesList(QuestionCardStatus.correctAnswer); + return; } + updateQuestionCardStatus(QuestionCardStatus.wrongAnswer); + updateAnswerStatusesList(QuestionCardStatus.wrongAnswer); } void resetValues() async { diff --git a/lib/ui/marathon/marathon_sponsor_video_screen.dart b/lib/ui/marathon/marathon_sponsor_video_screen.dart index 88c66f9..0bd8a1b 100644 --- a/lib/ui/marathon/marathon_sponsor_video_screen.dart +++ b/lib/ui/marathon/marathon_sponsor_video_screen.dart @@ -15,13 +15,13 @@ import 'package:video_player/video_player.dart'; class SponsorVideoScreen extends StatelessWidget { const SponsorVideoScreen({Key? key}) : super(key: key); - @override Widget build(BuildContext context) { MarathonProvider provider = context.watch(); return WillPopScope( onWillPop: () { - provider.videoController.dispose(); + provider.videoController.pause(); + provider.disposeVideoPlayer(); provider.sponsorsSecondsCounter = 0; provider.totalSponsorVideoSeconds = 0; provider.timerForSponsorVideo.cancel(); @@ -52,11 +52,12 @@ class SponsorVideoScreen extends StatelessWidget { child: provider.totalSponsorVideoSeconds == 0 ? InkWell( onTap: () { - provider.videoController.dispose(); + Navigator.pushReplacementNamed(context, AppRoutes.marathonIntroScreen); + provider.videoController.pause(); + provider.disposeVideoPlayer(); provider.sponsorsSecondsCounter = 0; provider.totalSponsorVideoSeconds = 0; provider.timerForSponsorVideo.cancel(); - Navigator.pushReplacementNamed(context, AppRoutes.marathonIntroScreen); }, child: const Icon(Icons.close, size: 12), ) @@ -73,11 +74,12 @@ class SponsorVideoScreen extends StatelessWidget { alignment: Alignment.topLeft, child: InkWell( onTap: () { - provider.videoController.dispose(); + Navigator.pushReplacementNamed(context, AppRoutes.marathonIntroScreen); + provider.videoController.pause(); + provider.disposeVideoPlayer(); provider.sponsorsSecondsCounter = 0; provider.totalSponsorVideoSeconds = 0; provider.timerForSponsorVideo.cancel(); - Navigator.pushReplacementNamed(context, AppRoutes.marathonIntroScreen); }, child: Container( decoration: BoxDecoration(color: MyColors.white, borderRadius: BorderRadius.circular(15)), diff --git a/lib/ui/marathon/widgets/countdown_timer_detail_screen.dart b/lib/ui/marathon/widgets/countdown_timer_detail_screen.dart index cbf9884..c12a452 100644 --- a/lib/ui/marathon/widgets/countdown_timer_detail_screen.dart +++ b/lib/ui/marathon/widgets/countdown_timer_detail_screen.dart @@ -201,6 +201,7 @@ class CountdownTimerForDetailScreen extends StatelessWidget { @override Widget build(BuildContext context) { return CountdownTimer( + // endTime: dummyTime, endTime: timeToMarathon, onEnd: null, widgetBuilder: (BuildContext context, CurrentRemainingTime? time) { diff --git a/lib/ui/marathon/widgets/marathon_banner.dart b/lib/ui/marathon/widgets/marathon_banner.dart index 1c4d6b8..f6adff6 100644 --- a/lib/ui/marathon/widgets/marathon_banner.dart +++ b/lib/ui/marathon/widgets/marathon_banner.dart @@ -11,6 +11,7 @@ import 'package:mohem_flutter_app/classes/decorations_helper.dart'; import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/extensions/int_extensions.dart'; +import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; import 'package:mohem_flutter_app/main.dart'; @@ -428,14 +429,17 @@ class MarathonBanner extends StatelessWidget { letterSpacing: -0.4, ), ), - Text( - AppState().isArabic(context) ? provider.marathonDetailModel.titleAr ?? "" : provider.marathonDetailModel.titleEn ?? "", - style: TextStyle( - fontStyle: FontStyle.italic, - fontSize: isTablet ? 30 : 19, - fontWeight: FontWeight.bold, - color: MyColors.white.withOpacity(0.83), - height: 32 / 22, + Flexible( + child: Text( + (AppState().isArabic(context) ? provider.marathonDetailModel.titleAr ?? "" : provider.marathonDetailModel.titleEn ?? "").trimString(15), + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontStyle: FontStyle.italic, + fontSize: isTablet ? 30 : 19, + fontWeight: FontWeight.bold, + color: MyColors.white.withOpacity(0.83), + height: 32 / 22, + ), ), ), isTablet ? 10.height : 3.height, diff --git a/lib/ui/marathon/widgets/marathon_details_card.dart b/lib/ui/marathon/widgets/marathon_details_card.dart index dda7ef8..11a3d84 100644 --- a/lib/ui/marathon/widgets/marathon_details_card.dart +++ b/lib/ui/marathon/widgets/marathon_details_card.dart @@ -53,14 +53,24 @@ class MarathonDetailsCard extends StatelessWidget { ? Row( children: [ "${LocaleKeys.prize.tr()} ".toText16(color: MyColors.grey77Color, isBold: true), - Row( - children: marathonDetailModel.sponsors!.first.sponsorPrizes! - .map( - (SponsorPrizes prizes) => - "${AppState().isArabic(context) ? prizes.marathonPrizeAr : prizes.marathonPrizeAr}".toText16(color: MyColors.greenColor, isBold: true).paddingOnly(right: 5), - ) - .toList(), - ), + Expanded( + child: SizedBox( + height: 30, + child: ListView.builder( + scrollDirection: Axis.horizontal, + shrinkWrap: true, + itemCount: marathonDetailModel.sponsors!.first.sponsorPrizes!.length, + itemBuilder: (BuildContext context, int index) { + SponsorPrizes prizes = marathonDetailModel.sponsors!.first.sponsorPrizes![index]; + return Container( + decoration: BoxDecoration(color: MyColors.backgroundColor, borderRadius: BorderRadius.circular(100), border: Border.all(color: MyColors.grey57Color.withOpacity(0.1))), + child: "${AppState().isArabic(context) ? prizes.marathonPrizeAr : prizes.marathonPrizeEn}" + .toText16(color: MyColors.greenColor, isBold: true) + .paddingOnly(left: 5, right: 5), + ).paddingOnly(left: 5); + }), + ), + ) ], ) : const SizedBox(), diff --git a/lib/ui/marathon/widgets/marathon_progress_container.dart b/lib/ui/marathon/widgets/marathon_progress_container.dart index 6a71b32..3de86ce 100644 --- a/lib/ui/marathon/widgets/marathon_progress_container.dart +++ b/lib/ui/marathon/widgets/marathon_progress_container.dart @@ -57,7 +57,7 @@ class MarathonProgressContainer extends StatelessWidget { ? getDemoMarathonerText() : "${provider.totalMarathoners} ${provider.totalMarathoners == 1 ? LocaleKeys.marathoner.tr() : LocaleKeys.marathoners.tr()}".toText14(), provider.questionCardStatus == QuestionCardStatus.question - ? "00:${(provider.totalCurrentQuestionTime - provider.currentGapTime) < 10 ? "0${provider.totalCurrentQuestionTime - provider.currentGapTime}" : provider.totalCurrentQuestionTime - provider.currentGapTime}" + ? "00:${provider.totalCurrentQuestionTime - provider.currentGapTime < 0 ? "00" : (provider.totalCurrentQuestionTime - provider.currentGapTime) < 10 ? "0${provider.totalCurrentQuestionTime - provider.currentGapTime}" : provider.totalCurrentQuestionTime - provider.currentGapTime}" .toText18(color: provider.totalCurrentQuestionTime - provider.currentGapTime < 5 ? MyColors.redColor : MyColors.black) : const SizedBox(), ],