import 'package:flutter/material.dart'; import 'package:ftc_mobile_app/ftc_mobile_app.dart'; import 'package:ftc_mobile_app/models/clients/HealthIssuesDetailsModel.dart'; import 'package:ftc_mobile_app/models/profileData/user_data.dart'; import 'package:ftc_mobile_app/utilities/extensions/custom_extensions.dart'; import 'package:get/get.dart'; import 'package:intl/intl.dart'; class IssueDetailPopupWidget extends StatefulWidget { const IssueDetailPopupWidget({ super.key, required this.userData, required this.data, this.canChangeStatus = true, this.canUpdate = true, this.onActionChange, this.onUpdateButtonTap, }); final UserData userData; final HealthIssueDetailsModel data; final bool canChangeStatus; final bool canUpdate; final Function(bool status, HealthIssueDetailsModel data)? onActionChange; final Function(HealthIssueDetailsModel data)? onUpdateButtonTap; static const actionActive = "Active"; static const actionResolved = "Resolved"; @override State createState() => _IssueDetailPopupWidgetState(); } class _IssueDetailPopupWidgetState extends State { final Map actionsMap = { IssueDetailPopupWidget.actionActive: true, IssueDetailPopupWidget.actionResolved: false }; String selectedValue = IssueDetailPopupWidget.actionActive; @override void initState() { selectedValue = widget.data.status ? IssueDetailPopupWidget.actionActive : IssueDetailPopupWidget.actionResolved; super.initState(); } @override Widget build(BuildContext context) { return Column( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start, children: [ SizedBox( width: Get.width, child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( width: double.maxFinite, padding: REdgeInsets.symmetric(horizontal: 12), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Health Note', style: TextStyle( fontSize: 12.sp, fontWeight: FontWeight.w400, ), ), CustomTextWidget( text: widget.data.healthNote, fontSize: 14.sp, fontWeight: FontWeight.bold, textAlign: TextAlign.left, isExpanded: false), ], ), ), Container( width: 90.r, height: 32.r, decoration: BoxDecoration( borderRadius: 24.toRadius(), color: (selectedValue == IssueDetailPopupWidget.actionActive) ? Colors.red.withOpacity(0.3) : Colors.green.withOpacity(0.3), ), child: IgnorePointer( ignoring: widget.canChangeStatus.not, child: DropdownButtonHideUnderline( child: DropdownButtonFormField( onTap: () { FocusScopeNode().unfocus(); }, value: selectedValue, dropdownColor: Colors.white, borderRadius: 4.toRadius(), decoration: InputDecoration( isDense: true, border: InputBorder.none, suffixIcon: Icon(Icons.arrow_drop_down_sharp, size: 18, color: (selectedValue == IssueDetailPopupWidget .actionActive) ? Colors.red : Colors.green) .paddingOnly(right: 12.r), suffixIconConstraints: BoxConstraints.tightFor( width: 24.r, height: 32.r), ), elevation: 4, icon: FrequentFunctions.noWidget, style: TextStyle( fontWeight: FontWeight.w400, fontSize: 10.sp, color: Colors.black), hint: Text( "Select...", style: TextStyle( fontWeight: FontWeight.w400, fontSize: 12.sp, color: CustomAppColors.kLightTextColor, ), ), selectedItemBuilder: (_) { return actionsMap.keys.map( (e) { return DropdownMenuItem( value: e, child: Container( alignment: Alignment.center, child: Text( e, style: TextStyle( color: (selectedValue == e) ? (selectedValue == IssueDetailPopupWidget .actionActive) ? Colors.red : Colors.green : Colors.black), ), ), ); }, ).toList(); }, items: actionsMap.keys .map( (e) => DropdownMenuItem( value: e, child: Text(e), ), ) .toList(), // padding: EdgeInsets.zero, isExpanded: true, onChanged: (v) { if (v != null) { setState(() { selectedValue = v; if (widget.onActionChange != null) { widget.onActionChange! .call(actionsMap[v]!, widget.data); } }); } }, ), ), ), ) ], ), ), 8.verticalSpace, Divider( height: 1, color: Colors.grey.withOpacity(0.3), ), Container( width: double.maxFinite, padding: REdgeInsets.symmetric(horizontal: 12, vertical: 12), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text.rich( textAlign: TextAlign.left, TextSpan( children: [ TextSpan( text: "Complaint: ", style: TextStyle( fontSize: 12.sp, fontWeight: FontWeight.w600), ), TextSpan( text: widget.data.complaint, style: TextStyle( fontSize: 12.sp, fontWeight: FontWeight.w400), ), ], ), ), 4.verticalSpace, Text.rich( textAlign: TextAlign.left, TextSpan( children: [ TextSpan( text: "Last Update: ", style: TextStyle( fontSize: 12.sp, fontWeight: FontWeight.w600), ), TextSpan( text: DateFormat("MMM/dd/yyyy").format( DateTime.parse(widget.data.updatedAt) .toLocal()), style: TextStyle( fontSize: 12.sp, fontWeight: FontWeight.w400), ), ], ), ), ], ), ), 16.verticalSpace, (widget.canUpdate) ? Center( child: SizedBox( width: 120.r, height: 32.r, child: CustomAppButton( onTap: (widget.onUpdateButtonTap == null) ? () {} : () => widget.onUpdateButtonTap!.call(widget.data), buttonText: "Update", ), ), ) : FrequentFunctions.noWidget, ], ), ), ], ); } }