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.
HMG_Patient_App_New/lib/presentation/profile_settings/profile_settings.dart

482 lines
23 KiB
Dart

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper_view/flutter_swiper_view.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/app_export.dart';
import 'package:hmg_patient_app_new/core/app_state.dart';
import 'package:hmg_patient_app_new/core/dependencies.dart';
import 'package:hmg_patient_app_new/core/enums.dart';
3 weeks ago
import 'package:hmg_patient_app_new/core/utils/date_util.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/int_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/habib_wallet/habib_wallet_view_model.dart';
import 'package:hmg_patient_app_new/features/insurance/insurance_view_model.dart';
import 'package:hmg_patient_app_new/features/medical_file/medical_file_view_model.dart';
import 'package:hmg_patient_app_new/features/medical_file/models/family_file_response_model.dart';
import 'package:hmg_patient_app_new/features/profile_settings/profile_settings_view_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/habib_wallet/habib_wallet_page.dart';
import 'package:hmg_patient_app_new/presentation/habib_wallet/recharge_wallet_page.dart';
import 'package:hmg_patient_app_new/services/dialog_service.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/app_language_change.dart';
3 weeks ago
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/chip/app_custom_chip_widget.dart';
import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart';
import 'package:hmg_patient_app_new/widgets/routes/custom_page_route.dart';
import 'package:provider/provider.dart';
import '../../core/dependencies.dart' show getIt;
class ProfileSettings extends StatefulWidget {
ProfileSettings({Key? key}) : super(key: key);
@override
_ProfileSettingsState createState() {
return _ProfileSettingsState();
}
}
class _ProfileSettingsState extends State<ProfileSettings> {
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();
}
1 week ago
double dynamicItemHeight(BuildContext context) {
final double w = SizeUtils.width;
final double h = SizeUtils.height;
double longer = w > h ? w : h;
double shorter = w < h ? w : h;
final double aspect = longer / (shorter == 0 ? 1 : shorter);
// Choose multiplier based on aspect ratio (handles near-square / foldable)
double multiplier;
if (aspect < 1.05) {
multiplier = 0.28; // nearly square / foldable -> smaller card height
} else if (aspect > 1.8) {
multiplier = 0.40; // very tall/wide -> larger height
} else {
multiplier = 0.34; // normal phones/tablets
}
// Compute and clamp using sensible bounds (uses .h extension)
final double minH = 210.h;
final double maxH = 380.h;
final double computed = (shorter * multiplier);
return computed.clamp(minH, maxH);
}
int length = 3;
final SwiperController _controller = SwiperController();
@override
Widget build(BuildContext context) {
return CollapsingListView(
title: "Profile & Settings".needTranslation,
logout: () {},
isClose: true,
child: SingleChildScrollView(
3 weeks ago
padding: EdgeInsets.only(top: 24.h, bottom: 24.h),
physics: NeverScrollableScrollPhysics(),
child: Consumer2<ProfileSettingsViewModel, MedicalFileViewModel>(
builder: (context, profileVm, medicalVm, child) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Swiper(
itemCount: medicalVm.patientFamilyFiles.length,
layout: SwiperLayout.STACK,
loop: true,
1 week ago
itemHeight: dynamicItemHeight(context),
itemWidth: SizeUtils.width - 30.w,
indicatorLayout: PageIndicatorLayout.COLOR,
axisDirection: AxisDirection.right,
controller: _controller,
3 weeks ago
pagination: SwiperPagination(
alignment: Alignment.bottomCenter,
3 weeks ago
margin: EdgeInsets.only(top: (210.h + 8.h + 24.h)),
builder: DotSwiperPaginationBuilder(color: Color(0xffD9D9D9), activeColor: AppColors.blackBgColor),
),
itemBuilder: (BuildContext context, int index) {
return FamilyCardWidget(
profile: medicalVm.patientFamilyFiles[index],
onAddFamilyMemberPress: () {
DialogService dialogService = getIt.get<DialogService>();
dialogService.showAddFamilyFileSheet(
label: "Add Family Member".needTranslation,
message: "Please fill the below field to add a new family member to your profile".needTranslation,
onVerificationPress: () {
medicalVm.addFamilyFile(otpTypeEnum: OTPTypeEnum.sms);
});
},
onFamilySwitchPress: (FamilyFileResponseModelLists profile) {
medicalVm.switchFamilyFiles(responseID: profile.responseId, patientID: profile.patientId, phoneNumber: profile.mobileNumber);
},
1 week ago
).paddingOnly(right: 16.w, left: 8.w);
},
),
1 week ago
SizedBox(height: 5.h),
GridView(
1 week ago
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: isTablet ? 3 : 2),
physics: const NeverScrollableScrollPhysics(),
1 week ago
padding: EdgeInsets.only(left: 24.w, right: 24.w, bottom: 24.h),
shrinkWrap: true,
children: [
Container(
3 weeks ago
padding: EdgeInsets.all(16.w),
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
color: AppColors.whiteColor,
3 weeks ago
borderRadius: 20.r,
hasShadow: true,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
1 week ago
// spacing: 4.h,
children: [
Row(
3 weeks ago
spacing: 8.w,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
3 weeks ago
Utils.buildSvgWithAssets(icon: AppAssets.wallet, width: 40.w, height: 40.h),
1 week ago
"Habib Wallet".needTranslation.toText16(weight: FontWeight.w600, maxlines: 2).expanded,
Utils.buildSvgWithAssets(icon: AppAssets.arrow_forward),
],
),
Spacer(),
Consumer<HabibWalletViewModel>(builder: (context, habibWalletVM, child) {
return Utils.getPaymentAmountWithSymbol2(habibWalletVM.habibWalletAmount, isExpanded: false)
3 weeks ago
.toShimmer2(isShow: habibWalletVM.isWalletAmountLoading, radius: 12.r, width: 80.w, height: 24.h);
}),
1 week ago
Spacer(),
CustomButton(
height: 40.h,
icon: AppAssets.recharge_icon,
1 week ago
iconSize: 22.w,
iconColor: AppColors.infoColor,
textColor: AppColors.infoColor,
1 month ago
text: "Recharge".needTranslation,
3 weeks ago
borderWidth: 0.w,
fontWeight: FontWeight.w500,
borderColor: Colors.transparent,
backgroundColor: Color(0xff45A2F8).withValues(alpha: 0.08),
3 weeks ago
padding: EdgeInsets.all(8.w),
fontSize: 14.f,
onPressed: () {
Navigator.of(context).push(CustomPageRoute(page: RechargeWalletPage()));
},
),
],
).onPress(() {
Navigator.of(context).push(CustomPageRoute(page: HabibWalletPage()));
}),
1 week ago
),
],
),
3 weeks ago
"Quick Actions"
.needTranslation
.toText18(weight: FontWeight.w600, textOverflow: TextOverflow.ellipsis, maxlines: 1)
.paddingOnly(left: 24.w, right: 24.w),
Container(
3 weeks ago
margin: EdgeInsets.only(left: 24.w, right: 24.w, top: 16.h, bottom: 24.h),
padding: EdgeInsets.only(top: 4.h, bottom: 4.h),
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.r, hasShadow: true),
child: Column(
children: [
actionItem(AppAssets.language_change, "Language".needTranslation, () {
3 weeks ago
showCommonBottomSheetWithoutHeight(context,
title: "Application Language".needTranslation, child: AppLanguageChange(), callBackFunc: () {}, isFullScreen: false);
}, trailingLabel: Utils.appState.isArabic() ? "العربية".needTranslation : "English".needTranslation),
1.divider,
actionItem(AppAssets.accessibility, "Accessibility".needTranslation, () {}),
1.divider,
actionItem(AppAssets.bell, "Notifications Settings".needTranslation, () {}),
1.divider,
actionItem(AppAssets.touch_face_id, "Touch ID / Face ID Services".needTranslation, () {}, switchValue: true),
],
),
),
3 weeks ago
"Personal Information"
.needTranslation
.toText18(weight: FontWeight.w600, textOverflow: TextOverflow.ellipsis, maxlines: 1)
.paddingOnly(left: 24.w, right: 24.w),
Container(
3 weeks ago
margin: EdgeInsets.only(left: 24.w, right: 24.w, top: 16.h, bottom: 24.h),
padding: EdgeInsets.only(top: 4.h, bottom: 4.h),
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.r, hasShadow: true),
child: Column(
children: [
actionItem(AppAssets.email_transparent, "Update Email Address".needTranslation, () {}),
1.divider,
actionItem(AppAssets.smart_phone_fill, "Phone Number".needTranslation, () {}),
1.divider,
actionItem(AppAssets.my_address, "My Addresses".needTranslation, () {}),
1.divider,
actionItem(AppAssets.emergency, "Emergency Contact".needTranslation, () {}),
],
),
),
3 weeks ago
"Help & Support"
.needTranslation
.toText18(weight: FontWeight.w600, textOverflow: TextOverflow.ellipsis, maxlines: 1)
.paddingOnly(left: 24.w, right: 24.w),
Container(
3 weeks ago
margin: EdgeInsets.only(left: 24.w, right: 24.w, top: 16.h),
padding: EdgeInsets.only(top: 4.h, bottom: 4.h),
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24.r, hasShadow: true),
child: Column(
children: [
actionItem(AppAssets.call_fill, "Contact Us".needTranslation, () {}, trailingLabel: "9200666666"),
1.divider,
actionItem(AppAssets.permission, "Permissions".needTranslation, () {}, trailingLabel: "Location, Camera"),
1.divider,
actionItem(AppAssets.rate, "Rate Our App".needTranslation, () {}, isExternalLink: true),
1.divider,
actionItem(AppAssets.privacy_terms, "Privacy Policy".needTranslation, () {}, isExternalLink: true),
1.divider,
actionItem(AppAssets.privacy_terms, "Terms & Conditions".needTranslation, () {}, isExternalLink: true),
],
),
),
1 week ago
CustomButton(
height: 56.h,
icon: AppAssets.minus,
text: "Deactivate account".needTranslation,
onPressed: () {},
).paddingAll(24.w),
],
);
},
),
),
);
}
Widget actionItem(String icon, String label, VoidCallback onPress, {String trailingLabel = "", bool? switchValue, bool isExternalLink = false}) {
return SizedBox(
3 weeks ago
height: 56.h,
child: Row(
3 weeks ago
spacing: 8.w,
children: [
Utils.buildSvgWithAssets(icon: icon, iconColor: AppColors.greyTextColor),
label.toText14(weight: FontWeight.w500, textOverflow: TextOverflow.ellipsis, maxlines: 1).expanded,
3 weeks ago
if (trailingLabel.isNotEmpty)
trailingLabel.toText14(color: AppColors.greyTextColor, weight: FontWeight.w500, textOverflow: TextOverflow.ellipsis, maxlines: 1),
switchValue != null
? Switch(
value: switchValue,
onChanged: (value) {},
3 weeks ago
activeThumbColor: AppColors.successColor,
activeTrackColor: AppColors.successColor.withValues(alpha: .15),
)
: Transform.scale(
scaleX: Utils.appState.isArabic() ? -1 : 1,
child: Utils.buildSvgWithAssets(icon: isExternalLink ? AppAssets.externalLink : AppAssets.arrow_forward),
)
],
3 weeks ago
).paddingOnly(left: 16.w, right: 16.w).onPress(onPress),
);
}
}
class FamilyCardWidget extends StatelessWidget {
final Function() onAddFamilyMemberPress;
final Function(FamilyFileResponseModelLists member) onFamilySwitchPress;
final FamilyFileResponseModelLists profile;
3 weeks ago
const FamilyCardWidget({
super.key,
required this.onAddFamilyMemberPress,
required this.profile,
required this.onFamilySwitchPress(FamilyFileResponseModelLists member),
});
@override
Widget build(BuildContext context) {
AppState appState = getIt.get<AppState>();
final isActive = (profile.responseId == appState.getAuthenticatedUser()?.patientId);
final isParentUser = appState.getAuthenticatedUser()?.isParentUser ?? false;
final canSwitch = isParentUser || (!isParentUser && profile.responseId == appState.getSuperUserID);
return Container(
1 week ago
decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
color: AppColors.whiteColor,
borderRadius: 24.r,
hasShadow: true,
),
child: Column(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 8.h,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
3 weeks ago
Image.asset(profile.gender == 1 ? AppAssets.male_img : AppAssets.femaleImg, width: 56.w, height: 56.h),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
"${profile.patientName}".toText18(isBold: true, weight: FontWeight.w600, textOverflow: TextOverflow.ellipsis, maxlines: 1),
AppCustomChipWidget(
icon: AppAssets.file_icon,
labelText: "${LocaleKeys.fileNo.tr(context: context)}: ${profile.responseId}",
3 weeks ago
iconSize: 12.w,
),
],
).expanded,
3 weeks ago
Icon(Icons.qr_code, size: 56.h)
],
),
SizedBox(height: 4.h),
SizedBox(
child: Wrap(
alignment: WrapAlignment.start,
3 weeks ago
spacing: 4.w,
runSpacing: 4.h,
children: [
3 weeks ago
AppCustomChipWidget(
labelText: "${profile.age} Years Old".needTranslation,
),
isActive && appState.getAuthenticatedUser()!.bloodGroup != null
? AppCustomChipWidget(
icon: AppAssets.blood_icon,
3 weeks ago
labelPadding: EdgeInsetsDirectional.only(start: -6.w, end: 8.w),
labelText: "Blood: ${appState.getAuthenticatedUser()!.bloodGroup ?? ""}",
iconColor: AppColors.primaryRedColor)
: SizedBox(),
Selector<InsuranceViewModel, ({bool isEmpty, int? patientID, bool isLoading, String? cardValidTo})>(
selector: (context, insuranceVM) => (
isEmpty: insuranceVM.patientInsuranceList.isEmpty,
patientID: insuranceVM.patientInsuranceList.isNotEmpty ? insuranceVM.patientInsuranceList.first.patientID : null,
isLoading: insuranceVM.isInsuranceLoading,
cardValidTo: insuranceVM.patientInsuranceList.isNotEmpty ? insuranceVM.patientInsuranceList.first.cardValidTo : null
),
builder: (context, data, child) {
if (data.isEmpty) {
return const SizedBox();
} else if (profile.responseId != data.patientID) {
return SizedBox();
}
final isLoading = data.isLoading;
final isExpired = !isLoading && DateTime.now().isAfter(DateUtil.convertStringToDate(data.cardValidTo));
final String icon;
final String labelText;
final Color iconColor;
final Color backgroundColor;
if (isLoading) {
icon = AppAssets.cancel_circle_icon;
labelText = "Insurance".needTranslation;
iconColor = AppColors.primaryRedColor;
backgroundColor = AppColors.primaryRedColor;
} else if (isExpired) {
icon = AppAssets.cancel_circle_icon;
labelText = "Insurance Expired".needTranslation;
iconColor = AppColors.primaryRedColor;
backgroundColor = AppColors.primaryRedColor.withValues(alpha: 0.15);
} else {
icon = AppAssets.insurance_active_icon;
labelText = "Insurance Active".needTranslation;
iconColor = AppColors.successColor;
backgroundColor = AppColors.successColor.withValues(alpha: 0.15);
}
return AppCustomChipWidget(
icon: icon,
labelText: labelText,
iconColor: iconColor,
3 weeks ago
iconSize: 12.w,
backgroundColor: backgroundColor,
3 weeks ago
labelPadding: EdgeInsetsDirectional.only(start: -6.w, end: 8.w),
// padding: EdgeInsets.zero,
).toShimmer2(isShow: isLoading);
},
)
],
),
),
],
3 weeks ago
).paddingOnly(top: 16.h, right: 16.w, left: 16.w, bottom: 12.h),
1.divider,
_buildActionButton(appState),
],
),
);
}
Widget _buildActionButton(AppState appState) {
final isParentUser = appState.getAuthenticatedUser()?.isParentUser ?? false;
final int? currentUserId = appState.getAuthenticatedUser()?.patientId;
final int? superUserId = appState.getSuperUserID;
if (isParentUser) {
return _buildParentUserButton(currentUserId);
} else {
return _buildNonParentUserButton(superUserId);
}
}
Widget _buildParentUserButton(int? currentUserId) {
final canSwitch = profile.responseId != currentUserId;
return CustomButton(
icon: canSwitch ? AppAssets.switch_user : AppAssets.add_family,
text: canSwitch ? "Switch Family File".needTranslation : "Add a new family member".needTranslation,
onPressed: canSwitch ? () => onFamilySwitchPress(profile) : onAddFamilyMemberPress,
backgroundColor: canSwitch ? AppColors.secondaryLightRedColor : AppColors.primaryRedColor,
borderColor: canSwitch ? AppColors.secondaryLightRedColor : AppColors.primaryRedColor,
textColor: canSwitch ? AppColors.primaryRedColor : AppColors.whiteColor,
iconColor: canSwitch ? AppColors.primaryRedColor : AppColors.whiteColor,
1 week ago
height: isFoldable ? 50.h : 40.h,
3 weeks ago
fontSize: 14.f,
).paddingOnly(top: 12.h, right: 16.w, left: 16.w, bottom: 16.h);
}
Widget _buildNonParentUserButton(int? superUserId) {
final canSwitchBack = superUserId != null && superUserId == profile.responseId;
return CustomButton(
icon: AppAssets.switch_user,
text: canSwitchBack ? "Switch Back To Family File".needTranslation : "Switch".needTranslation,
backgroundColor: canSwitchBack ? AppColors.primaryRedColor : Colors.grey.shade200,
borderColor: canSwitchBack ? AppColors.primaryRedColor : Colors.grey.shade200,
textColor: canSwitchBack ? AppColors.whiteColor : AppColors.greyTextColor,
iconColor: canSwitchBack ? AppColors.whiteColor : AppColors.greyTextColor,
onPressed: canSwitchBack ? () => onFamilySwitchPress(profile) : () {},
1 week ago
height: isFoldable ? 50.h : 40.h,
3 weeks ago
fontSize: 14.f,
).paddingOnly(top: 12.h, right: 16.w, left: 16.w, bottom: 16.h);
}
// //TODO: Add family file switch logic here
// isRootUser
// ? CustomButton(icon: AppAssets.add_family, text: "Add a new family member".needTranslation, height: 40.h, fontSize: 14, onPressed: () {})
// .paddingOnly(top: 12, right: 16, left: 16, bottom: 16)
// : CustomButton(
// icon: AppAssets.add_family,
// backgroundColor: AppColors.secondaryLightRedColor,
// borderColor: AppColors.secondaryLightRedColor,
// textColor: AppColors.primaryRedColor,
// iconColor: AppColors.primaryRedColor,
// text: "Switch to this medical file".needTranslation,
// height: 40.h,
// fontSize: 14,
// onPressed: () {})
// .paddingOnly(top: 12, right: 16, left: 16, bottom: 16),
//
}