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.
		
		
		
		
		
			
		
			
				
	
	
		
			217 lines
		
	
	
		
			9.0 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			217 lines
		
	
	
		
			9.0 KiB
		
	
	
	
		
			Dart
		
	
| import 'dart:developer';
 | |
| 
 | |
| import 'package:appinio_swiper/appinio_swiper.dart';
 | |
| import 'package:easy_localization/easy_localization.dart';
 | |
| import 'package:flutter/cupertino.dart';
 | |
| import 'package:flutter/material.dart';
 | |
| import 'package:lottie/lottie.dart';
 | |
| import 'package:mohem_flutter_app/app_state/app_state.dart';
 | |
| import 'package:mohem_flutter_app/classes/colors.dart';
 | |
| import 'package:mohem_flutter_app/classes/decorations_helper.dart';
 | |
| import 'package:mohem_flutter_app/classes/lottie_consts.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/disclosure/disclosure_question_model.dart';
 | |
| import 'package:mohem_flutter_app/ui/disclosure/disclosure_provider.dart';
 | |
| import 'package:mohem_flutter_app/widgets/dynamic_forms/dynamic_textfield_widget.dart';
 | |
| import 'package:provider/provider.dart';
 | |
| 
 | |
| class DisclosureQuestionCard extends StatelessWidget {
 | |
|   const DisclosureQuestionCard({Key? key}) : super(key: key);
 | |
| 
 | |
|   @override
 | |
|   Widget build(BuildContext context) {
 | |
|     DisclosureProvider provider = context.read<DisclosureProvider>();
 | |
|     return CupertinoPageScaffold(
 | |
|       child: provider.cardContentList.isEmpty
 | |
|           ? Lottie.asset(MyLottieConsts.hourGlassLottie, height: 250).paddingOnly(top: 50)
 | |
|           : Consumer<DisclosureProvider>(
 | |
|               builder: (BuildContext context, DisclosureProvider provider, Widget? child) {
 | |
|                 return Container(
 | |
|                   constraints: BoxConstraints(minHeight: MediaQuery.of(context).size.height * .43),
 | |
|                   height: (provider.currentQuestionSelectionStatus == DisclosureQuestionsOptionStatus.correct && provider.currentQuestionNumber != provider.disclosureDetailsModel.totalQuestions!)
 | |
|                       ? MediaQuery.of(context).size.height * .6
 | |
|                       : MediaQuery.of(context).size.height * .43,
 | |
|                   width: double.infinity,
 | |
|                   child: AppinioSwiper(
 | |
|                     duration: const Duration(milliseconds: 400),
 | |
|                     padding: EdgeInsets.zero,
 | |
|                     isDisabled: true,
 | |
|                     controller: provider.swiperController,
 | |
|                     unswipe: (int index, AppinioSwiperDirection direction) {},
 | |
|                     onSwipe: (int index, AppinioSwiperDirection direction) {},
 | |
|                     cards: provider.cardContentList,
 | |
|                   ),
 | |
|                 );
 | |
|               },
 | |
|             ),
 | |
|     );
 | |
|   }
 | |
| }
 | |
| 
 | |
| class DisclosureCardContent extends StatelessWidget {
 | |
|   const DisclosureCardContent({Key? key}) : super(key: key);
 | |
| 
 | |
|   @override
 | |
|   Widget build(BuildContext context) {
 | |
|     DisclosureProvider provider = context.watch<DisclosureProvider>();
 | |
|     return Container(
 | |
|       decoration: BoxDecoration(
 | |
|         borderRadius: BorderRadius.circular(10),
 | |
|         color: CupertinoColors.white,
 | |
|         boxShadow: <BoxShadow>[
 | |
|           BoxShadow(
 | |
|             color: CupertinoColors.systemGrey.withOpacity(0.2),
 | |
|             spreadRadius: 3,
 | |
|             blurRadius: 7,
 | |
|             offset: const Offset(0, 3),
 | |
|           )
 | |
|         ],
 | |
|       ),
 | |
|       alignment: Alignment.center,
 | |
|       child: Column(
 | |
|         children: <Widget>[
 | |
|           Flexible(
 | |
|             child: Container(
 | |
|               width: double.infinity,
 | |
|               decoration: const BoxDecoration(
 | |
|                 borderRadius: BorderRadius.only(
 | |
|                   topLeft: Radius.circular(10),
 | |
|                   topRight: Radius.circular(10),
 | |
|                 ),
 | |
|               ),
 | |
|               constraints: BoxConstraints(minHeight: MediaQuery.of(context).size.height * .23),
 | |
|               child: Padding(
 | |
|                 padding: const EdgeInsets.only(left: 15, right: 15, top: 15),
 | |
|                 child: SingleChildScrollView(
 | |
|                   child: Text(
 | |
|                     displayLocalizedContent(
 | |
|                       isPhoneLangArabic: AppState().isArabic(context),
 | |
|                       selectedLanguage: (provider.disclosureDetailsModel.selectedLanguage) ?? 0,
 | |
|                       englishContent: provider.currentQuestion.titleEn ?? "",
 | |
|                       arabicContent: provider.currentQuestion.titleAr ?? "",
 | |
|                     ),
 | |
|                     style: const TextStyle(
 | |
|                       color: MyColors.darkTextColor,
 | |
|                       fontSize: 15,
 | |
|                       height: 21 / 14,
 | |
|                       fontWeight: FontWeight.w500,
 | |
|                     ),
 | |
|                   ),
 | |
|                 ),
 | |
|               ),
 | |
|             ),
 | |
|           ),
 | |
|           24.height,
 | |
|           const DisclosureAnswerContent(),
 | |
|         ],
 | |
|       ),
 | |
|     );
 | |
|   }
 | |
| }
 | |
| 
 | |
| class DisclosureAnswerContent extends StatelessWidget {
 | |
|   const DisclosureAnswerContent({Key? key}) : super(key: key);
 | |
| 
 | |
|   @override
 | |
|   Widget build(BuildContext context) {
 | |
|     DisclosureProvider provider = context.watch<DisclosureProvider>();
 | |
|     return Container(
 | |
|       padding: const EdgeInsets.only(bottom: 20, left: 8, right: 8),
 | |
|       decoration: const BoxDecoration(
 | |
|         color: MyColors.kWhiteColor,
 | |
|         borderRadius: BorderRadius.only(bottomLeft: Radius.circular(10), bottomRight: Radius.circular(10)),
 | |
|       ),
 | |
|       child: provider.currentQuestion.questionOptions != null
 | |
|           ? Column(
 | |
|               children: [
 | |
|                 Row(
 | |
|                   children: List<Widget>.generate(
 | |
|                     provider.currentQuestion.questionOptions!.length,
 | |
|                     (int index) => Expanded(
 | |
|                       child: DisclosureAnswerTileForText(
 | |
|                         index: index,
 | |
|                         onAnswerTapped: () => provider.updateCurrentQuestionOptionStatus(status: DisclosureQuestionsOptionStatus.selected, selectedOptIndex: index, correctOptionIndex: -1), //
 | |
|                       ).paddingAll(8),
 | |
|                     ),
 | |
|                   ),
 | |
|                 ),
 | |
|                 if (provider.currentQuestionSelectionStatus == DisclosureQuestionsOptionStatus.correct && provider.currentQuestionNumber != provider.disclosureDetailsModel.totalQuestions!) ...[
 | |
|                   15.height,
 | |
|                   Text(
 | |
|                     displayLocalizedContent(
 | |
|                       isPhoneLangArabic: AppState().isArabic(context),
 | |
|                       selectedLanguage: (provider.disclosureDetailsModel.selectedLanguage) ?? 0,
 | |
|                       englishContent: provider.currentQuestion.descEn ?? "",
 | |
|                       arabicContent: provider.currentQuestion.descAr ?? "",
 | |
|                     ),
 | |
|                     style: const TextStyle(
 | |
|                       color: MyColors.darkTextColor,
 | |
|                       fontSize: 14,
 | |
|                       height: 21 / 14,
 | |
|                       fontWeight: FontWeight.w500,
 | |
|                     ),
 | |
|                   ).paddingOnly(left: 8, right: 8),
 | |
|                   8.height,
 | |
|                   DynamicTextFieldWidget(
 | |
|                     LocaleKeys.pleaseWriteHere.tr(),
 | |
|                     provider.currentAdditionalText,
 | |
|                     lines: 3,
 | |
|                     onChange: (value) {
 | |
|                       provider.updateCurrentAdditionalText(value);
 | |
|                     },
 | |
|                   ).paddingOnly(left: 8, right: 8),
 | |
|                 ],
 | |
|               ],
 | |
|             )
 | |
|           : const SizedBox(),
 | |
|     );
 | |
|   }
 | |
| }
 | |
| 
 | |
| class DisclosureAnswerTileForText extends StatelessWidget {
 | |
|   final int index;
 | |
|   final Function() onAnswerTapped;
 | |
| 
 | |
|   const DisclosureAnswerTileForText({Key? key, required this.index, required this.onAnswerTapped}) : super(key: key);
 | |
| 
 | |
|   Color getAnswerTextColor(DisclosureQuestionsOptionStatus status) {
 | |
|     switch (status) {
 | |
|       case DisclosureQuestionsOptionStatus.correct:
 | |
|         return MyColors.white;
 | |
|       case DisclosureQuestionsOptionStatus.wrong:
 | |
|         return MyColors.white;
 | |
|       case DisclosureQuestionsOptionStatus.selected:
 | |
|         return MyColors.white;
 | |
|       case DisclosureQuestionsOptionStatus.unSelected:
 | |
|         return MyColors.darkTextColor;
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   @override
 | |
|   Widget build(BuildContext context) {
 | |
|     DisclosureProvider provider = context.watch<DisclosureProvider>();
 | |
|     return InkWell(
 | |
|       onTap: () => onAnswerTapped(),
 | |
|       child: Container(
 | |
|         alignment: Alignment.centerLeft,
 | |
|         decoration: MyDecorations.getAnswersContainerColorForDisclosure(
 | |
|           provider.currentQuestion.questionOptions![index].optionStatus!,
 | |
|           isLastQuestion: provider.currentQuestionNumber == provider.disclosureDetailsModel.totalQuestions!,
 | |
|           isAgreeSelected: provider.selectedOptionIndex == 0,
 | |
|         ),
 | |
|         child: Center(
 | |
|           child: displayLocalizedContent(
 | |
|             isPhoneLangArabic: AppState().isArabic(context),
 | |
|             selectedLanguage: (provider.disclosureDetailsModel.selectedLanguage) ?? 0,
 | |
|             englishContent: provider.currentQuestion.questionOptions![index].titleEn ?? "",
 | |
|             arabicContent: provider.currentQuestion.questionOptions![index].titleAr ?? "",
 | |
|           ).toText16(color: getAnswerTextColor(provider.currentQuestion.questionOptions![index].optionStatus!)).paddingOnly(top: 13, bottom: 13),
 | |
|         ),
 | |
|       ),
 | |
|     );
 | |
|   }
 | |
| }
 |