Pushing for testing

merge-requests/104/head
Faiz Hashmi 3 years ago
parent c1be522331
commit 58fb7a7894

@ -97,6 +97,7 @@ class MarathonApiClient {
if (marathonModel.statusCode == 208) { if (marathonModel.statusCode == 208) {
// means participant is already in the marathon i.e already joined // means participant is already in the marathon i.e already joined
//TODO: NEED TO LOOK UPON THIS
return marathonModel.data["remainingTime"]; return marathonModel.data["remainingTime"];
} }
@ -116,13 +117,13 @@ class MarathonApiClient {
Map<String, String?> jsonObject = <String, String?>{ Map<String, String?> jsonObject = <String, String?>{
"previousQuestionId": questionId, "previousQuestionId": questionId,
"marathonId": marathonId, "marathonId": marathonId,
}; };
Response response = await ApiClient().postJsonForResponse(ApiConsts.marathonNextQuestionUrl, jsonObject, token: AppState().getMarathonToken ?? await getMarathonToken()); Response response = await ApiClient().postJsonForResponse(ApiConsts.marathonNextQuestionUrl, jsonObject, token: AppState().getMarathonToken ?? await getMarathonToken());
var json = jsonDecode(response.body); var json = jsonDecode(response.body);
logger.i("json in NextQuestion: $json"); logger.i("json in NextQuestion: $json");
var data = json["data"]; var data = json["data"];

@ -31,6 +31,11 @@ class MarathonProvider extends ChangeNotifier {
String? selectedOptionId; String? selectedOptionId;
int? totalQualifiers; int? totalQualifiers;
//TODO: THIS BUG NEEDS TO BE FIXED. NOT DONE YET
String? gapTimeImage;
String? gapTimeText;
int? gapTimeType;
bool iAmWinner = false; bool iAmWinner = false;
bool isPrivilegedWithMarathon = false; bool isPrivilegedWithMarathon = false;
@ -178,16 +183,21 @@ class MarathonProvider extends ChangeNotifier {
updateCardStatusToAnswer(); updateCardStatusToAnswer();
await callSubmitOptionApi().then((bool value) async { scheduleMicrotask(() async {
if (value) { await callSubmitOptionApi().then((bool value) async {
await callNextQuestionApi(); if (value) {
} await callNextQuestionApi();
}
});
}); });
} }
if (totalCurrentQuestionTime == 0) { if (totalCurrentQuestionTime == 0) {
gapTimeImage = currentQuestion.gapImage;
gapTimeText = currentQuestion.gapText;
gapTimeType = currentQuestion.gapType;
updateCardData(); updateCardData();
if (currentQuestionNumber == marathonDetailModel.totalQuestions!) { if (currentQuestionNumber - 1 == marathonDetailModel.totalQuestions!) {
callGetQualifiersApi(); callGetQualifiersApi();
updateQuestionCardStatus(QuestionCardStatus.findingWinner); updateQuestionCardStatus(QuestionCardStatus.findingWinner);
timer.cancel(); timer.cancel();
@ -242,7 +252,6 @@ class MarathonProvider extends ChangeNotifier {
selectedWinners = await MarathonApiClient().getSelectedWinner(marathonId: marathonDetailModel.id!); selectedWinners = await MarathonApiClient().getSelectedWinner(marathonId: marathonDetailModel.id!);
if (selectedWinners != null) { if (selectedWinners != null) {
selectedWinners!.removeWhere((WinnerModel element) { selectedWinners!.removeWhere((WinnerModel element) {
print("matching : ${AppState().memberInformationList!.eMPLOYEENUMBER} with ${element.employeeId}");
if (element.employeeId == AppState().memberInformationList!.eMPLOYEENUMBER) { if (element.employeeId == AppState().memberInformationList!.eMPLOYEENUMBER) {
iAmWinner = true; iAmWinner = true;
return true; return true;
@ -251,18 +260,18 @@ class MarathonProvider extends ChangeNotifier {
} }
}); });
} }
print("selectedWinners Length : ${selectedWinners!.length}");
notifyListeners(); notifyListeners();
} }
// TODO: here I need to add a logic where I should call this function for Api but for the 1st question it should behave differently
// TODO: Verify the callings!!!
Future<void> callNextQuestionApi() async { Future<void> callNextQuestionApi() async {
if (currentQuestionNumber < marathonDetailModel.totalQuestions!) { if (currentQuestionNumber < marathonDetailModel.totalQuestions!) {
if (currentQuestionNumber == 0) { if (currentQuestionNumber == 0) {
Utils.showLoading(AppRoutes.navigatorKey.currentContext!); Utils.showLoading(AppRoutes.navigatorKey.currentContext!);
currentQuestion = (await MarathonApiClient().getNextQuestion(questionId: null, marathonId: marathonDetailModel.id!))!; currentQuestion = (await MarathonApiClient().getNextQuestion(questionId: null, marathonId: marathonDetailModel.id!))!;
gapTimeImage = currentQuestion.gapImage;
gapTimeText = currentQuestion.gapText;
gapTimeType = currentQuestion.gapType;
if (Utils.isLoading) { if (Utils.isLoading) {
Utils.hideLoading(AppRoutes.navigatorKey.currentContext!); Utils.hideLoading(AppRoutes.navigatorKey.currentContext!);
} }
@ -283,6 +292,7 @@ class MarathonProvider extends ChangeNotifier {
} }
selectedOptionIndex = null; selectedOptionIndex = null;
currentQuestionNumber++; currentQuestionNumber++;
cardContentList.add(const CardContent()); cardContentList.add(const CardContent());
totalCurrentQuestionTime = currentQuestion.questionTime! + currentQuestion.nextQuestGap!; totalCurrentQuestionTime = currentQuestion.questionTime! + currentQuestion.nextQuestGap!;
currentGapTime = currentQuestion.nextQuestGap!; currentGapTime = currentQuestion.nextQuestGap!;
@ -293,7 +303,7 @@ class MarathonProvider extends ChangeNotifier {
void populateQuestionStatusesList() { void populateQuestionStatusesList() {
if (marathonDetailModel.totalQuestions != null) { if (marathonDetailModel.totalQuestions != null) {
for (int i = 0; i < marathonDetailModel.totalQuestions! - 1; i++) { for (int i = 0; i < marathonDetailModel.totalQuestions!; i++) {
answerStatusesList.add(QuestionCardStatus.question); answerStatusesList.add(QuestionCardStatus.question);
} }
notifyListeners(); notifyListeners();
@ -422,9 +432,6 @@ class MarathonProvider extends ChangeNotifier {
Navigator.pushReplacementNamed(context, AppRoutes.marathonWaitingScreen); Navigator.pushReplacementNamed(context, AppRoutes.marathonWaitingScreen);
} }
} catch (e) { } catch (e) {
if (kDebugMode) {
print("error in onJoinMarathonPressed: ${e.toString()}");
}
Utils.hideLoading(context); Utils.hideLoading(context);
Utils.confirmDialog(context, e.toString()); Utils.confirmDialog(context, e.toString());
} }

@ -22,6 +22,7 @@ import 'package:mohem_flutter_app/ui/marathon/widgets/marathon_qualifiers_contai
import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart'; import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart';
import 'package:mohem_flutter_app/ui/marathon/widgets/question_card_builder.dart'; import 'package:mohem_flutter_app/ui/marathon/widgets/question_card_builder.dart';
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart'; import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
import 'package:mohem_flutter_app/widgets/button/default_button.dart';
import 'package:mohem_flutter_app/widgets/dialogs/confirm_dialog.dart'; import 'package:mohem_flutter_app/widgets/dialogs/confirm_dialog.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -197,57 +198,74 @@ class MarathonScreen extends StatelessWidget {
} }
}, },
), ),
body: SingleChildScrollView( body: Column(
child: Column( children: <Widget>[
children: <Widget>[ ListView(
20.height, children: [
if (provider.questionCardStatus == QuestionCardStatus.findingWinner) ...<Widget>[ 20.height,
QualifiersContainer(provider: provider).paddingOnly(left: 21, right: 21), if (provider.questionCardStatus == QuestionCardStatus.findingWinner) ...<Widget>[
] else if (provider.questionCardStatus == QuestionCardStatus.winnerFound) QualifiersContainer(provider: provider).paddingOnly(left: 21, right: 21),
...<Widget>[] ] else if (provider.questionCardStatus == QuestionCardStatus.winnerFound)
else ...<Widget>[ ...<Widget>[]
MarathonProgressContainer(provider: provider).paddingOnly(left: 21, right: 21), else ...<Widget>[
], MarathonProgressContainer(provider: provider).paddingOnly(left: 21, right: 21),
if (provider.questionCardStatus == QuestionCardStatus.findingWinner) ...<Widget>[ ],
getNameContainer(context), if (provider.questionCardStatus == QuestionCardStatus.findingWinner) ...<Widget>[
getNameContainer(context),
],
QuestionCardBuilder(
onQuestion: (BuildContext context) => const QuestionCard(),
onCompleted: (BuildContext context) => CustomStatusWidget(
asset: Lottie.asset(MyLottieConsts.allQuestions, height: 200),
title: LocaleKeys.congrats.tr().toText22(color: MyColors.greenColor),
subTitle: LocaleKeys.allQuestionsCorrect.toText18(color: MyColors.darkTextColor, isCentered: true),
),
onCorrectAnswer: (BuildContext context) => CustomStatusWidget(
asset: getSuccessWidget(gapType: provider.gapTimeType, gapImage: provider.gapTimeImage, gapText: provider.gapTimeText),
title: LocaleKeys.congrats.tr().toText22(color: MyColors.greenColor),
subTitle: LocaleKeys.yourAnswerCorrect.tr().toText18(color: MyColors.darkTextColor, isCentered: true),
),
onWinner: (BuildContext context) => getWinnerWidget(context, provider: provider),
onWrongAnswer: (BuildContext context) => CustomStatusWidget(
asset: Image.asset(MyLottieConsts.wrongAnswerGif, height: 200),
title: LocaleKeys.oops.tr().toText22(color: MyColors.redColor),
subTitle: LocaleKeys.wrongAnswer.tr().toText18(color: MyColors.darkTextColor, isCentered: true),
),
onSkippedAnswer: (BuildContext context) => CustomStatusWidget(
asset: Image.asset(MyLottieConsts.wrongAnswerGif, height: 200),
title: LocaleKeys.oops.tr().toText22(color: MyColors.redColor),
subTitle: LocaleKeys.youMissedTheQuestion.tr().toText18(color: MyColors.darkTextColor, isCentered: true),
),
onFindingWinner: (BuildContext context) => CustomStatusWidget(
asset: Lottie.asset(MyLottieConsts.winnerLottie, height: 168),
title: LocaleKeys.fingersCrossed.tr().toText22(color: MyColors.greenColor),
subTitle: LocaleKeys.winnerSelectedRandomly.tr().toText18(color: MyColors.darkTextColor, isCentered: true),
),
questionCardStatus: provider.questionCardStatus,
).paddingOnly(top: 12, left: 21, right: 21),
], ],
QuestionCardBuilder( ).expanded,
onQuestion: (BuildContext context) => const QuestionCard(), provider.questionCardStatus == QuestionCardStatus.winnerFound
onCompleted: (BuildContext context) => CustomStatusWidget( ? DefaultButton(LocaleKeys.ok.tr(), () {
asset: Lottie.asset(MyLottieConsts.allQuestions, height: 200), provider.resetValues();
title: LocaleKeys.congrats.tr().toText22(color: MyColors.greenColor), Navigator.of(context).popUntil(ModalRoute.withName(AppRoutes.dashboard));
subTitle: LocaleKeys.allQuestionsCorrect.toText18(color: MyColors.darkTextColor, isCentered: true), }).insideContainer
), : const SizedBox()
onCorrectAnswer: (BuildContext context) => CustomStatusWidget( ],
asset: getSuccessWidget(gapType: provider.currentQuestion.gapType, gapImage: provider.currentQuestion.gapImage, gapText: provider.currentQuestion.gapText),
title: LocaleKeys.congrats.tr().toText22(color: MyColors.greenColor),
subTitle: LocaleKeys.yourAnswerCorrect.toText18(color: MyColors.darkTextColor, isCentered: true),
),
onWinner: (BuildContext context) => getWinnerWidget(context, provider: provider),
onWrongAnswer: (BuildContext context) => CustomStatusWidget(
asset: Image.asset(MyLottieConsts.wrongAnswerGif, height: 200),
title: LocaleKeys.oops.tr().toText22(color: MyColors.redColor),
subTitle: LocaleKeys.wrongAnswer.tr().toText18(color: MyColors.darkTextColor, isCentered: true),
),
onSkippedAnswer: (BuildContext context) => CustomStatusWidget(
asset: Image.asset(MyLottieConsts.wrongAnswerGif, height: 200),
title: LocaleKeys.oops.tr().toText22(color: MyColors.redColor),
subTitle: LocaleKeys.youMissedTheQuestion.tr().toText18(color: MyColors.darkTextColor, isCentered: true),
),
onFindingWinner: (BuildContext context) => CustomStatusWidget(
asset: Lottie.asset(MyLottieConsts.winnerLottie, height: 168),
title: LocaleKeys.fingersCrossed.tr().toText22(color: MyColors.greenColor),
subTitle: LocaleKeys.winnerSelectedRandomly.tr().toText18(color: MyColors.darkTextColor, isCentered: true),
),
questionCardStatus: provider.questionCardStatus,
).paddingOnly(top: 12, left: 21, right: 21),
],
),
), ),
), ),
onWillPop: () { onWillPop: () {
provider.resetValues(); showDialog(
return Future<bool>.value(true); context: context,
builder: (BuildContext context) => ConfirmDialog(
message: LocaleKeys.youWantToLeaveMarathon.tr(),
onTap: () {
provider.resetValues();
Navigator.of(context).popUntil(ModalRoute.withName(AppRoutes.dashboard));
},
),
);
return Future<bool>.value(false);
}, },
); );
} }

@ -47,20 +47,3 @@ class MarathonFooter extends StatelessWidget {
).insideContainer; ).insideContainer;
} }
} }
//Container(
// color: Colors.white,
// child: Column(
// mainAxisSize: MainAxisSize.min,
// children: <Widget>[
// buildNoteForDemo(),
// DefaultButton(
// LocaleKeys.joinDemoMarathon.tr(),
// () {
// provider.connectSignalrAndJoinMarathon(context);
// },
// color: MyColors.yellowColorII,
// ).insideContainer,
// ],
// ),
// );

@ -43,7 +43,8 @@ class MarathonProgressContainer extends StatelessWidget {
8.height, 8.height,
Row( Row(
children: <Widget>[ children: <Widget>[
"${((provider.currentQuestionNumber / provider.marathonDetailModel.totalQuestions!) * 100).toInt()}% ${LocaleKeys.completed.tr()}".toText14(), "${provider.currentQuestionNumber == 1 ? 0 : (((provider.currentQuestionNumber - 1) / provider.marathonDetailModel.totalQuestions!) * 100).toInt()}% ${LocaleKeys.completed.tr()}"
.toText14(),
], ],
), ),
], ],
@ -52,9 +53,6 @@ class MarathonProgressContainer extends StatelessWidget {
} }
Color getStepColor(QuestionCardStatus status, bool isOutOfGame) { Color getStepColor(QuestionCardStatus status, bool isOutOfGame) {
if (isOutOfGame) {
return MyColors.redColor;
}
switch (status) { switch (status) {
case QuestionCardStatus.question: case QuestionCardStatus.question:
return MyColors.yellowColorII; return MyColors.yellowColorII;
@ -79,7 +77,7 @@ class MarathonProgressContainer extends StatelessWidget {
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
for (int i = 0; i < totalQuestions - 1; i++) for (int i = 0; i < totalQuestions; i++)
if (value <= i) if (value <= i)
roundContainer(MyColors.lightGreyDeColor, i != 0) roundContainer(MyColors.lightGreyDeColor, i != 0)
else else

@ -43,6 +43,7 @@ class _QualifiersContainerState extends State<QualifiersContainer> {
), ),
10.height, 10.height,
Row( Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[ children: <Widget>[
widget.provider.totalQualifiers != null ? widget.provider.totalQualifiers.toString().toText30(color: MyColors.greenColor, isBold: true) : const SizedBox(), widget.provider.totalQualifiers != null ? widget.provider.totalQualifiers.toString().toText30(color: MyColors.greenColor, isBold: true) : const SizedBox(),
2.width, 2.width,

Loading…
Cancel
Save