418 lines
16 KiB
Dart
418 lines
16 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:onufitness/constants/asset_constants.dart';
|
|
import 'package:onufitness/constants/color_constant.dart';
|
|
import 'package:onufitness/constants/constant.dart';
|
|
import 'package:onufitness/constants/string_constant.dart';
|
|
import 'package:onufitness/constants/text_constant.dart';
|
|
import 'package:onufitness/controller/get_user_data_controller.dart';
|
|
import 'package:onufitness/controller/notification_controller.dart';
|
|
import 'package:onufitness/routes/route_constant.dart';
|
|
import 'package:onufitness/screens/accounts/Controllers/edit_account_controller.dart';
|
|
import 'package:onufitness/screens/accounts/Controllers/my_account_controller.dart';
|
|
import 'package:onufitness/screens/accounts/widgets/become_a_coach_button_card.dart';
|
|
import 'package:onufitness/screens/accounts/widgets/coach_application_status_button.dart';
|
|
import 'package:onufitness/screens/chat/controllers/chat_controller.dart';
|
|
import 'package:onufitness/screens/register/Controllers/social_login_controller.dart';
|
|
import 'package:onufitness/services/local_storage_services/shared_services.dart';
|
|
import 'package:onufitness/services/notification_services/notification_service.dart';
|
|
import 'package:onufitness/utils/custom_sneakbar.dart';
|
|
import 'package:onufitness/widgets/others/button_action_bottom_sheet.dart';
|
|
import 'package:onufitness/screens/accounts/widgets/my_account_features_tile_card.dart';
|
|
import 'package:onufitness/utils/helper_function.dart';
|
|
import 'package:onufitness/widgets/Buttons/custom_social_login_button.dart';
|
|
|
|
class TraineeMyAccountScreen extends StatefulWidget {
|
|
const TraineeMyAccountScreen({super.key});
|
|
|
|
@override
|
|
State<TraineeMyAccountScreen> createState() => _TraineeMyAccountScreenState();
|
|
}
|
|
|
|
class _TraineeMyAccountScreenState extends State<TraineeMyAccountScreen> {
|
|
// Use late final for all controllers
|
|
late final SocialLoginController socialLoginController;
|
|
late final GetUserDetailsController getUserDetailsController;
|
|
late final MyAccountController controller;
|
|
late final NotificationController notificationController;
|
|
late final NotificationService notificationService;
|
|
late final ChatController chatController;
|
|
late final EditAccountController editAccountController;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
// Initialize SocialLoginController
|
|
if (!Get.isRegistered<SocialLoginController>()) {
|
|
Get.put(SocialLoginController());
|
|
}
|
|
socialLoginController = Get.find<SocialLoginController>();
|
|
|
|
// Initialize GetUserDetailsController
|
|
if (!Get.isRegistered<GetUserDetailsController>()) {
|
|
Get.put(GetUserDetailsController());
|
|
}
|
|
getUserDetailsController = Get.find<GetUserDetailsController>();
|
|
|
|
// Initialize MyAccountController
|
|
if (!Get.isRegistered<MyAccountController>()) {
|
|
Get.put(MyAccountController());
|
|
}
|
|
controller = Get.find<MyAccountController>();
|
|
|
|
// Initialize NotificationController
|
|
if (!Get.isRegistered<NotificationController>()) {
|
|
Get.put(NotificationController());
|
|
}
|
|
notificationController = Get.find<NotificationController>();
|
|
|
|
// // Initialize NotificationService
|
|
// if (!Get.isRegistered<NotificationService>()) {
|
|
// Get.put(NotificationService());
|
|
// }
|
|
notificationService = Get.find<NotificationService>();
|
|
|
|
// Initialize ChatController
|
|
if (!Get.isRegistered<ChatController>()) {
|
|
Get.put(ChatController());
|
|
}
|
|
chatController = Get.find<ChatController>();
|
|
|
|
// Initialize EditAccountController
|
|
if (!Get.isRegistered<EditAccountController>()) {
|
|
Get.put(EditAccountController());
|
|
}
|
|
editAccountController = Get.find<EditAccountController>();
|
|
|
|
// API calls
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
apicall();
|
|
});
|
|
}
|
|
|
|
apicall() async {
|
|
await editAccountController.fetchUserDetails();
|
|
await getUserDetailsController.fetchUserDetails();
|
|
}
|
|
|
|
Widget coachStatusWidget() {
|
|
return Obx(() {
|
|
if (getUserDetailsController.isUserDetailsFetchedLoading.value) {
|
|
return Center(child: CircularProgressIndicator());
|
|
}
|
|
|
|
final status = getUserDetailsController.becomeCoachStatus.value;
|
|
|
|
// Show status button only for Pending and Approved
|
|
if (status == "Pending") {
|
|
return coachStatusButton(
|
|
status: "Pending",
|
|
statusText: status,
|
|
onTap: () {
|
|
customSnackbar(
|
|
title: "Application Pending",
|
|
message:
|
|
"Your coach application is currently under review. We'll notify you once it's processed.",
|
|
);
|
|
},
|
|
);
|
|
} else if (status == "Approved") {
|
|
return coachStatusButton(
|
|
status: "Approved",
|
|
statusText: status,
|
|
onTap: () {
|
|
customSnackbar(
|
|
title: "Congratulations!",
|
|
message:
|
|
"Your coach application has been approved. Please log out and log in again to access your coach profile.",
|
|
duration: 5,
|
|
);
|
|
},
|
|
);
|
|
} else if (status == "Rejected") {
|
|
return coachStatusButton(
|
|
status: "Rejected",
|
|
statusText: status,
|
|
onTap: () async {
|
|
// Refresh user details when returning from Become a Coach screen
|
|
final result = await Get.toNamed(RouteConstant.becomeACoachScreen);
|
|
if (result == true) {
|
|
// Refresh the status after returning
|
|
await getUserDetailsController.fetchUserDetails();
|
|
}
|
|
},
|
|
);
|
|
} else {
|
|
return becomeCoachCard(
|
|
onTap: () async {
|
|
final result = await Get.toNamed(RouteConstant.becomeACoachScreen);
|
|
if (result == true) {
|
|
await getUserDetailsController.fetchUserDetails();
|
|
}
|
|
},
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: pageBackGroundColor,
|
|
appBar: AppBar(
|
|
backgroundColor: appBarBackgroundColor,
|
|
title: Text(
|
|
accountAppBarText,
|
|
style: TextStyle(
|
|
fontSize: appBarHeardingText,
|
|
fontWeight: FontWeight.w600,
|
|
color: appbarTextColor,
|
|
),
|
|
),
|
|
automaticallyImplyLeading: false,
|
|
actions: [
|
|
Stack(
|
|
children: [
|
|
IconButton(
|
|
icon: Icon(
|
|
Icons.notifications_none,
|
|
color: Colors.black,
|
|
size: 24.sp,
|
|
),
|
|
onPressed: () {
|
|
notificationController.fetchNotifications(isRefresh: true);
|
|
Get.toNamed(RouteConstant.notificationListScreen);
|
|
},
|
|
),
|
|
notificationController.hasUnreadNotifications
|
|
? Positioned(
|
|
right: isTablet ? 5.w : 12.w,
|
|
top: isTablet ? 6.h : 12.h,
|
|
child: Container(
|
|
width: 8.r,
|
|
height: 8.r,
|
|
decoration: BoxDecoration(
|
|
color: Colors.red,
|
|
shape: BoxShape.circle,
|
|
),
|
|
),
|
|
)
|
|
: SizedBox(),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
body: LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
return SingleChildScrollView(
|
|
padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 15.h),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
padding: EdgeInsets.symmetric(vertical: 15.h),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
border: Border.all(color: containerBorderColor),
|
|
borderRadius: BorderRadius.circular(20.r),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
blurRadius: 1,
|
|
color: Color(outlineButtonBorderColorSky),
|
|
spreadRadius: 1,
|
|
offset: Offset(0, 3),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
children: [
|
|
accountMenuItem(
|
|
AssetConstants.myAccount,
|
|
myProfileText,
|
|
() {
|
|
Get.toNamed(RouteConstant.traineeMyProfile);
|
|
},
|
|
),
|
|
isTablet ? SizedBox(height: 10.h) : Container(),
|
|
Padding(
|
|
padding: EdgeInsets.only(left: 45.w),
|
|
child: Divider(
|
|
color: Color(outlineButtonBorderColorSky),
|
|
),
|
|
),
|
|
accountMenuItem(AssetConstants.rise, riseText, () {
|
|
Get.toNamed(RouteConstant.challengeListScreen);
|
|
}),
|
|
isTablet ? SizedBox(height: 10.h) : Container(),
|
|
Padding(
|
|
padding: EdgeInsets.only(left: 45.w),
|
|
child: Divider(
|
|
color: Color(outlineButtonBorderColorSky),
|
|
),
|
|
),
|
|
accountMenuItem(AssetConstants.uVault, uVaultText, () {
|
|
Get.toNamed(RouteConstant.viewUvault);
|
|
}),
|
|
isTablet ? SizedBox(height: 10.h) : Container(),
|
|
Padding(
|
|
padding: EdgeInsets.only(left: 45.w),
|
|
child: Divider(
|
|
color: Color(outlineButtonBorderColorSky),
|
|
),
|
|
),
|
|
// accountMenuItem(
|
|
// AssetConstants.achievements,
|
|
// achievementsText,
|
|
// () {
|
|
// Get.toNamed(RouteConstant.traineeAchievementScreen);
|
|
// },
|
|
// ),
|
|
// isTablet ? SizedBox(height: 10.h) : Container(),
|
|
// Padding(
|
|
// padding: EdgeInsets.only(left: 45.w),
|
|
// child: Divider(
|
|
// color: Color(outlineButtonBorderColorSky),
|
|
// ),
|
|
// ),
|
|
accountMenuItem(
|
|
AssetConstants.myActivity,
|
|
termsAndContionTileText,
|
|
() {
|
|
Get.toNamed(RouteConstant.traineetermsAndConditions);
|
|
},
|
|
),
|
|
isTablet ? SizedBox(height: 10.h) : Container(),
|
|
Padding(
|
|
padding: EdgeInsets.only(left: 45.w),
|
|
child: Divider(
|
|
color: Color(outlineButtonBorderColorSky),
|
|
),
|
|
),
|
|
accountMenuItem(
|
|
AssetConstants.privacyPolicy,
|
|
privicyPolicyTileText,
|
|
() {
|
|
Get.toNamed(RouteConstant.privecyPolicyScreen);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
SizedBox(height: isTablet ? 40.h : 20.h),
|
|
|
|
// Use the new method to build coach status widget
|
|
coachStatusWidget(),
|
|
|
|
SizedBox(height: isTablet ? 40.h : 20.h),
|
|
|
|
Center(
|
|
child: Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 0.2.sw),
|
|
child: CustomSocialLoginButton(
|
|
borderSide: BorderSide(color: greyBorderColorLight),
|
|
height: isTablet ? 70.h : 55.h,
|
|
text: logoutText,
|
|
textColor: Colors.black,
|
|
fontSize: 18.sp,
|
|
fontWeight: FontWeight.w600,
|
|
onPressed: () async {
|
|
await actionButtonBottomSheet(
|
|
context: context,
|
|
title: "Are you sure you want to Logout ?",
|
|
subtitle: "This action cannot be undone.",
|
|
submitButtonText: "Logout",
|
|
isLoading: controller.isLogoutLoading,
|
|
assetPath: AssetConstants.delete,
|
|
primaryColor: Color(primaryColor),
|
|
cancelBorderColor: greyBorderColorLight,
|
|
onPressed: () async {
|
|
await socialLoginController.logout();
|
|
await controller.logout().then((value) async {
|
|
if (value) {
|
|
await chatController.logout();
|
|
await notificationService.deleteDeviceToken();
|
|
await SharedServices.logout();
|
|
Get.offNamedUntil(
|
|
RouteConstant.loginFirstScreen,
|
|
(route) => false,
|
|
);
|
|
}
|
|
});
|
|
},
|
|
cancelButtonText: "Cancel",
|
|
onCancelPressed: () {
|
|
Get.back();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: isTablet ? 30.h : 20.h),
|
|
|
|
Center(
|
|
child: TextButton(
|
|
onPressed: () {
|
|
actionButtonBottomSheet(
|
|
context: context,
|
|
title: "Are you sure you want to delete your account?",
|
|
subtitle: "This action cannot be undone.",
|
|
submitButtonText: "Delete Request",
|
|
onPressed: () {
|
|
editAccountController.deleteUserAccount().then((
|
|
value,
|
|
) async {
|
|
if (value == true) {
|
|
await socialLoginController.logout();
|
|
await chatController.logout();
|
|
await notificationService.deleteDeviceToken();
|
|
await SharedServices.logout();
|
|
Get.offNamedUntil(
|
|
RouteConstant.loginFirstScreen,
|
|
(route) => false,
|
|
);
|
|
|
|
Future.delayed(Duration(milliseconds: 300), () {
|
|
customSnackbar(
|
|
title: "Account Deleted",
|
|
message:
|
|
"Your account has been successfully deleted. If you wish to recover it, please contact our support team.",
|
|
);
|
|
});
|
|
}
|
|
});
|
|
},
|
|
cancelButtonText: "Cancel",
|
|
onCancelPressed: () {
|
|
Get.back();
|
|
},
|
|
assetPath: AssetConstants.delete,
|
|
primaryColor: Color(primaryColor),
|
|
cancelBorderColor: greyBorderColorLight,
|
|
isLoading: editAccountController.isAccountDeleting,
|
|
);
|
|
},
|
|
child: Text(
|
|
"Delete your account",
|
|
style: TextStyle(
|
|
fontSize: regularSizeText,
|
|
color: Color(deleteAccountTextColorRed),
|
|
fontWeight: FontWeight.w600,
|
|
fontFamily: montserratFontFamily,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 30.h),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|