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

@ -31,6 +31,11 @@ class MarathonProvider extends ChangeNotifier {
String? selectedOptionId;
int? totalQualifiers;
//TODO: THIS BUG NEEDS TO BE FIXED. NOT DONE YET
String? gapTimeImage;
String? gapTimeText;
int? gapTimeType;
bool iAmWinner = false;
bool isPrivilegedWithMarathon = false;
@ -178,16 +183,21 @@ class MarathonProvider extends ChangeNotifier {
updateCardStatusToAnswer();
await callSubmitOptionApi().then((bool value) async {
if (value) {
await callNextQuestionApi();
}
scheduleMicrotask(() async {
await callSubmitOptionApi().then((bool value) async {
if (value) {
await callNextQuestionApi();
}
});
});
}
if (totalCurrentQuestionTime == 0) {
gapTimeImage = currentQuestion.gapImage;
gapTimeText = currentQuestion.gapText;
gapTimeType = currentQuestion.gapType;
updateCardData();
if (currentQuestionNumber == marathonDetailModel.totalQuestions!) {
if (currentQuestionNumber - 1 == marathonDetailModel.totalQuestions!) {
callGetQualifiersApi();
updateQuestionCardStatus(QuestionCardStatus.findingWinner);
timer.cancel();
@ -242,7 +252,6 @@ class MarathonProvider extends ChangeNotifier {
selectedWinners = await MarathonApiClient().getSelectedWinner(marathonId: marathonDetailModel.id!);
if (selectedWinners != null) {
selectedWinners!.removeWhere((WinnerModel element) {
print("matching : ${AppState().memberInformationList!.eMPLOYEENUMBER} with ${element.employeeId}");
if (element.employeeId == AppState().memberInformationList!.eMPLOYEENUMBER) {
iAmWinner = true;
return true;
@ -251,18 +260,18 @@ class MarathonProvider extends ChangeNotifier {
}
});
}
print("selectedWinners Length : ${selectedWinners!.length}");
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 {
if (currentQuestionNumber < marathonDetailModel.totalQuestions!) {
if (currentQuestionNumber == 0) {
Utils.showLoading(AppRoutes.navigatorKey.currentContext!);
currentQuestion = (await MarathonApiClient().getNextQuestion(questionId: null, marathonId: marathonDetailModel.id!))!;
gapTimeImage = currentQuestion.gapImage;
gapTimeText = currentQuestion.gapText;
gapTimeType = currentQuestion.gapType;
if (Utils.isLoading) {
Utils.hideLoading(AppRoutes.navigatorKey.currentContext!);
}
@ -283,6 +292,7 @@ class MarathonProvider extends ChangeNotifier {
}
selectedOptionIndex = null;
currentQuestionNumber++;
cardContentList.add(const CardContent());
totalCurrentQuestionTime = currentQuestion.questionTime! + currentQuestion.nextQuestGap!;
currentGapTime = currentQuestion.nextQuestGap!;
@ -293,7 +303,7 @@ class MarathonProvider extends ChangeNotifier {
void populateQuestionStatusesList() {
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);
}
notifyListeners();
@ -422,9 +432,6 @@ class MarathonProvider extends ChangeNotifier {
Navigator.pushReplacementNamed(context, AppRoutes.marathonWaitingScreen);
}
} catch (e) {
if (kDebugMode) {
print("error in onJoinMarathonPressed: ${e.toString()}");
}
Utils.hideLoading(context);
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_builder.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:provider/provider.dart';
@ -197,57 +198,74 @@ class MarathonScreen extends StatelessWidget {
}
},
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
20.height,
if (provider.questionCardStatus == QuestionCardStatus.findingWinner) ...<Widget>[
QualifiersContainer(provider: provider).paddingOnly(left: 21, right: 21),
] else if (provider.questionCardStatus == QuestionCardStatus.winnerFound)
...<Widget>[]
else ...<Widget>[
MarathonProgressContainer(provider: provider).paddingOnly(left: 21, right: 21),
],
if (provider.questionCardStatus == QuestionCardStatus.findingWinner) ...<Widget>[
getNameContainer(context),
body: Column(
children: <Widget>[
ListView(
children: [
20.height,
if (provider.questionCardStatus == QuestionCardStatus.findingWinner) ...<Widget>[
QualifiersContainer(provider: provider).paddingOnly(left: 21, right: 21),
] else if (provider.questionCardStatus == QuestionCardStatus.winnerFound)
...<Widget>[]
else ...<Widget>[
MarathonProgressContainer(provider: provider).paddingOnly(left: 21, right: 21),
],
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(
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.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),
],
),
).expanded,
provider.questionCardStatus == QuestionCardStatus.winnerFound
? DefaultButton(LocaleKeys.ok.tr(), () {
provider.resetValues();
Navigator.of(context).popUntil(ModalRoute.withName(AppRoutes.dashboard));
}).insideContainer
: const SizedBox()
],
),
),
onWillPop: () {
provider.resetValues();
return Future<bool>.value(true);
showDialog(
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;
}
}
//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,
Row(
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) {
if (isOutOfGame) {
return MyColors.redColor;
}
switch (status) {
case QuestionCardStatus.question:
return MyColors.yellowColorII;
@ -79,7 +77,7 @@ class MarathonProgressContainer extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
for (int i = 0; i < totalQuestions - 1; i++)
for (int i = 0; i < totalQuestions; i++)
if (value <= i)
roundContainer(MyColors.lightGreyDeColor, i != 0)
else

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

Loading…
Cancel
Save