import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:hmg_patient_app_new/core/app_export.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/extensions/route_extensions.dart'; import 'package:hmg_patient_app_new/extensions/string_extensions.dart'; import 'package:hmg_patient_app_new/extensions/widget_extensions.dart'; import 'package:hmg_patient_app_new/features/symptoms_checker/data/triage_questions_data.dart'; import 'package:hmg_patient_app_new/features/symptoms_checker/models/triage_question_model.dart'; import 'package:hmg_patient_app_new/generated/locale_keys.g.dart'; import 'package:hmg_patient_app_new/presentation/symptoms_checker/widgets/custom_progress_bar.dart'; import 'package:hmg_patient_app_new/theme/colors.dart'; import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart'; import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart'; import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart'; class TriageScreen extends StatefulWidget { const TriageScreen({super.key}); @override State createState() => _TriageScreenState(); } class _TriageScreenState extends State { late List triageQuestions; int currentQuestionIndex = 0; @override void initState() { super.initState(); triageQuestions = TriageQuestionsData.getSampleTriageQuestions(); } TriageQuestionModel get currentQuestion => triageQuestions[currentQuestionIndex]; bool get isFirstQuestion => currentQuestionIndex == 0; bool get isLastQuestion => currentQuestionIndex == triageQuestions.length - 1; void _onOptionSelected(int optionIndex) { setState(() { currentQuestion.selectOption(optionIndex); }); } void _onPreviousPressed() { if (!isFirstQuestion) { setState(() { currentQuestionIndex--; }); } } void _onNextPressed() { if (currentQuestion.isAnswered) { currentQuestion.confirmSelection(); if (isLastQuestion) { context.navigateWithName(AppRoutes.possibleConditionsScreen); } else { setState(() { currentQuestionIndex++; }); } } else { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Please select an option before proceeding'.needTranslation), backgroundColor: AppColors.errorColor, ), ); } } _buildConfirmationBottomSheet({required BuildContext context, required VoidCallback onConfirm}) { return showCommonBottomSheetWithoutHeight( title: LocaleKeys.notice.tr(context: context), context, child: Utils.getWarningWidget( loadingText: "Are you sure you want to restart the organ selection?".needTranslation, isShowActionButtons: true, onCancelTap: () => Navigator.pop(context), onConfirmTap: () => onConfirm(), ), callBackFunc: () {}, isFullScreen: false, isCloseButtonVisible: true, ); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppColors.bgScaffoldColor, body: Column( children: [ Expanded( child: CollapsingListView( title: "Triage".needTranslation, // onLeadingTapped: () => _buildConfirmationBottomSheet( // context: context, // onConfirm: () => { // context.pop(), // context.pop(), // }), leadingCallback: () => context.pop(), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox(height: 16.h), _buildQuestionCard(), ], ), ), ), _buildStickyBottomCard(context), ], ), ); } Widget _buildQuestionCard() { return AnimatedSwitcher( duration: const Duration(milliseconds: 400), transitionBuilder: (Widget child, Animation animation) { final offsetAnimation = Tween( begin: const Offset(1.0, 0.0), end: Offset.zero, ).animate(CurvedAnimation( parent: animation, curve: Curves.easeInOut, )); return SlideTransition( position: offsetAnimation, child: FadeTransition( opacity: animation, child: child, ), ); }, child: Container( key: ValueKey(currentQuestionIndex), width: double.infinity, margin: EdgeInsets.symmetric(horizontal: 24.w), decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.r), padding: EdgeInsets.symmetric(vertical: 24.h, horizontal: 20.w), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ currentQuestion.question.toText16(weight: FontWeight.w500), SizedBox(height: 24.h), ...List.generate(currentQuestion.options.length, (index) { bool selected = currentQuestion.selectedOptionIndex == index; return _buildOptionItem(index, selected, currentQuestion.options[index].text); }), ], ), ), ); } Widget _buildOptionItem(int index, bool selected, String optionText) { return GestureDetector( onTap: () => _onOptionSelected(index), child: Container( margin: EdgeInsets.only(bottom: 12.h), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ AnimatedContainer( duration: const Duration(milliseconds: 300), curve: Curves.easeInOut, width: 24.w, height: 24.w, decoration: BoxDecoration( color: selected ? AppColors.primaryRedColor : Colors.transparent, borderRadius: BorderRadius.circular(5.r), border: Border.all(color: selected ? AppColors.primaryRedColor : AppColors.checkBoxBorderColor, width: 1.w), ), child: selected ? Icon(Icons.check, size: 16.f, color: AppColors.whiteColor) : null, ), SizedBox(width: 12.w), Expanded(child: optionText.toText14(weight: FontWeight.w500)), ], ), ), ); } Widget _buildStickyBottomCard(BuildContext context) { final currentScore = TriageQuestionsData.calculateTotalScore(triageQuestions); final suggestedCondition = TriageQuestionsData.getSuggestedCondition(currentScore); return Container( decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.r), child: Column( mainAxisSize: MainAxisSize.min, children: [ SizedBox(height: 16.h), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ RichText( text: TextSpan( text: "Possible symptom: ".needTranslation, style: TextStyle( color: AppColors.greyTextColor, fontWeight: FontWeight.w600, fontSize: 14.f, ), children: [ TextSpan( text: suggestedCondition, style: TextStyle( color: AppColors.textColor, fontWeight: FontWeight.w600, fontSize: 14.f, ), ), ], ), ), SizedBox(height: 16.h), CustomRoundedProgressBar( percentage: currentScore, paddingBetween: 5.h, color: AppColors.primaryRedColor, backgroundColor: AppColors.primaryRedColor.withValues(alpha: 0.17), height: 8.h, titleWidget: RichText( text: TextSpan( text: "$currentScore% ", style: TextStyle( color: AppColors.primaryRedColor, fontWeight: FontWeight.w600, fontSize: 14.f, ), children: [ TextSpan( text: "- Symptoms checker finding score".needTranslation, style: TextStyle( color: AppColors.textColor, fontWeight: FontWeight.w500, fontSize: 13.f, ), ), ], ), ), ), SizedBox(height: 12.h), Row( children: [ Expanded( child: CustomButton( text: "Previous".needTranslation, onPressed: isFirstQuestion ? () {} : _onPreviousPressed, isDisabled: isFirstQuestion, backgroundColor: AppColors.primaryRedColor.withValues(alpha: 0.11), borderColor: Colors.transparent, textColor: AppColors.primaryRedColor, fontSize: 16.f, ), ), SizedBox(width: 12.w), Expanded( child: CustomButton( text: isLastQuestion ? "Finish".needTranslation : "Next".needTranslation, onPressed: _onNextPressed, backgroundColor: AppColors.primaryRedColor, borderColor: AppColors.primaryRedColor, textColor: AppColors.whiteColor, fontSize: 16.f, ), ), ], ), ], ), SizedBox(height: 24.h), ], ).paddingSymmetrical(24.w, 0), ); } }