You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
4.2 KiB
Dart
114 lines
4.2 KiB
Dart
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:mohem_flutter_app/classes/colors.dart';
|
|
import 'package:mohem_flutter_app/classes/decorations_helper.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/models/marathon/question_model.dart';
|
|
import 'package:mohem_flutter_app/ui/marathon/marathon_provider.dart';
|
|
|
|
class MarathonProgressContainer extends StatelessWidget {
|
|
final MarathonProvider provider;
|
|
|
|
const MarathonProgressContainer({Key? key, required this.provider}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
width: double.infinity,
|
|
decoration: MyDecorations.shadowDecoration,
|
|
padding: const EdgeInsets.symmetric(vertical: 18, horizontal: 13),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: <Widget>[
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: <Widget>[
|
|
Container(
|
|
decoration: BoxDecoration(color: MyColors.greenColor, borderRadius: BorderRadius.circular(5)),
|
|
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 8),
|
|
child: "${provider.currentQuestionNumber.toString()} / ${provider.marathonDetailModel.totalQuestions.toString()} ${LocaleKeys.question.tr()}".toText12(color: MyColors.white),
|
|
),
|
|
"${provider.totalMarathoners} ${LocaleKeys.marathoners.tr()}".toText14(),
|
|
"00:${provider.currentQuestionTime < 10 ? "0${provider.currentQuestionTime}" : provider.currentQuestionTime}"
|
|
.toText18(color: provider.currentQuestionTime < 5 ? MyColors.redColor : MyColors.black),
|
|
],
|
|
),
|
|
12.height,
|
|
stepper(provider.currentQuestionNumber, provider.answerStatusesList, provider.marathonDetailModel.totalQuestions!, provider.isUserOutOfGame),
|
|
8.height,
|
|
Row(
|
|
children: <Widget>[
|
|
"${((provider.currentQuestionNumber / provider.marathonDetailModel.totalQuestions!) * 100).toInt()}% ${LocaleKeys.completed.tr()}".toText14(),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Color getStepColor(QuestionCardStatus status, bool isOutOfGame) {
|
|
if (isOutOfGame) {
|
|
return MyColors.redColor;
|
|
}
|
|
switch (status) {
|
|
case QuestionCardStatus.question:
|
|
return MyColors.yellowColorII;
|
|
case QuestionCardStatus.wrongAnswer:
|
|
return MyColors.redColor;
|
|
case QuestionCardStatus.correctAnswer:
|
|
return MyColors.greenColor;
|
|
case QuestionCardStatus.skippedAnswer:
|
|
return MyColors.redColor;
|
|
case QuestionCardStatus.completed:
|
|
return MyColors.lightGreyDeColor;
|
|
case QuestionCardStatus.findingWinner:
|
|
return MyColors.lightGreyDeColor;
|
|
case QuestionCardStatus.winnerFound:
|
|
return MyColors.lightGreyDeColor;
|
|
}
|
|
}
|
|
|
|
Widget stepper(int value, List<QuestionCardStatus> statusesList, int totalQuestions, bool isOutOfGame) {
|
|
return SizedBox(
|
|
width: double.infinity,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: <Widget>[
|
|
for (int i = 0; i < totalQuestions - 1; i++)
|
|
if (value <= i)
|
|
roundContainer(MyColors.lightGreyDeColor, i != 0)
|
|
else
|
|
roundContainer(
|
|
getStepColor(statusesList[i], isOutOfGame),
|
|
i != 0,
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget roundContainer(Color color, bool isNeedLeftBorder) {
|
|
if (isNeedLeftBorder) {
|
|
return Row(
|
|
children: [
|
|
Divider(thickness: 6, color: color).expanded,
|
|
Container(
|
|
width: 10,
|
|
height: 10,
|
|
decoration: BoxDecoration(shape: BoxShape.circle, color: color),
|
|
),
|
|
],
|
|
).expanded;
|
|
}
|
|
|
|
return Container(
|
|
width: 10,
|
|
height: 10,
|
|
decoration: BoxDecoration(shape: BoxShape.circle, color: color),
|
|
);
|
|
}
|
|
}
|