import 'dart:io'; import 'package:dotted_line/dotted_line.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:nearledaily/view/account/share_app.dart'; import 'package:nearledaily/view/authentication/login_view.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:shimmer/shimmer.dart'; import '../../constants/color_constants.dart'; import '../../constants/font_constants.dart'; import '../../controllers/account_controller/profile.dart'; import '../../controllers/authentication/auth_controller.dart'; import '../../domain/repository/authentication/auth_repository.dart'; import '../../service/bindings.dart'; import '../../widgets/text_widget.dart'; import '../orders/orders_by_tenant.dart'; import 'edit_profile_view.dart'; import 'faq_view.dart'; import 'help/create_request.dart'; import 'notification_settings_view.dart'; class AccountPage extends StatefulWidget { const AccountPage({super.key}); @override State createState() => _AccountPageState(); } class _AccountPageState extends State { static const Color primaryColor = Color(0xFF662582); final controller = Get.put(AccountController()); String Name = ''; String Profile = ''; String Number = ''; @override void initState() { super.initState(); _loadProfile(); } Future _loadProfile() async { SharedPreferences prefs = await SharedPreferences.getInstance(); int? id = prefs.getInt('customerId'); if (id == null) return; final repo = LoginRepository(); final fetchedProfile = await repo.fetchProfile(id.toString()); if (fetchedProfile != null) { setState(() { Name = fetchedProfile.firstname ?? ''; Profile = fetchedProfile.profileimage ?? ''; Number = fetchedProfile.contactno ?? ''; }); print(Name); print(Profile); print(Number); } } Widget _profileShimmer() { return Container( margin: const EdgeInsets.all(16), padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(16), ), child: Row( children: [ Shimmer.fromColors( baseColor: Colors.grey.shade300, // shimmer base highlightColor: Colors.grey.shade100, // shimmer highlight child: CircleAvatar( radius: 28, backgroundColor: Colors.grey.shade200, // light background child: Icon( Icons.person, size: 28, color: Colors.grey.shade500, // darker icon color ), ), ), const SizedBox(width: 12), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Shimmer.fromColors( baseColor: Colors.grey[300]!, highlightColor: Colors.grey[100]!, child: Container( height: 14, width: 120, decoration: BoxDecoration( color: Colors.white, // <-- background color goes here borderRadius: BorderRadius.circular(8), // <-- rounded corners ), ), ), const SizedBox(height: 6), Shimmer.fromColors( baseColor: Colors.grey[300]!, highlightColor: Colors.grey[100]!, child: Container( height: 12, width: 90, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(8), // <-- add radius here too ), ), ), ], ) ], ), ); } @override Widget build(BuildContext context) { SystemChrome.setSystemUIOverlayStyle( const SystemUiOverlayStyle( statusBarColor: Colors.white, // or transparent statusBarIconBrightness: Brightness.dark, // Android statusBarBrightness: Brightness.light, // iOS ), ); return SafeArea( child: Scaffold( extendBodyBehindAppBar: false, backgroundColor: Color(0xFFF6F6F6), appBar: AppBar( backgroundColor: Colors.white, surfaceTintColor: Colors.transparent, // ๐Ÿ”ฅ Prevent color overlay when scrolled scrolledUnderElevation: 0, animateColor: false, // โœจ prevent color change on scroll elevation: 0, title: ReusableTextWidget( text: "Profile", fontSize: 20, fontWeight: FontWeight.w600, fontFamily: FontConstants.fontFamily, color: Colors.black, ), ), body: Obx( () => SingleChildScrollView( physics: const ClampingScrollPhysics(), child: Column( children: [ const SizedBox(height: 20), /// PROFILE CARD (EXACT LIKE IMAGE) controller.isLoading.value ? _profileShimmer() : GestureDetector( onTap: () async { final res = await Get.to( () => EditProfilePage(), // transition: Transition.fade, // Your desired transition // duration: Duration(milliseconds: 400), // Duration of the transition ); if (res != null && res['status'] == true) { _loadProfile(); } }, child: Container( margin: const EdgeInsets.symmetric(horizontal: 11), padding: const EdgeInsets.only( left: 16, right: 16, top: 30, bottom: 30, ), decoration: BoxDecoration( gradient: LinearGradient( colors: [ Color(0xFF1B1333), // Dark background (luxury dark purple/indigo) Color(0xFF662582).withOpacity(0.9), // Primary color accent ], begin: Alignment.topLeft, end: Alignment.bottomRight, ), borderRadius: BorderRadius.circular(16), border: Border.all( color: Colors.black12, width: 0.30 ), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.03), blurRadius: 2, offset: const Offset(0, 3), ), ], ), child: Row( children: [ CircleAvatar( radius: 28, backgroundColor: Colors.grey.shade300, backgroundImage: Profile.isNotEmpty ? NetworkImage(Profile) : null, child: Profile.isEmpty ? const Icon(Icons.person, size: 26) : null, ), const SizedBox(width: 14), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ ReusableTextWidget( text: Name, fontSize: 16, fontWeight: FontWeight.w600, fontFamily: FontConstants.fontFamily, color: Colors.white, ), const SizedBox(height: 4), ReusableTextWidget( text: Number, fontSize: 13, fontWeight: FontWeight.w400, fontFamily: FontConstants.fontFamily, color: Colors.white, ), ], ), ), ], ), ), ), const SizedBox(height: 24), /// ACCOUNT controller.isLoading.value ? accountListShimmerSingleBox() : _section( title: "Account", children: [ _tile( icon: Icons.person, title: "Manage Profile", onTap: () async { final res = await Get.to( () => EditProfilePage(), // transition: Transition.fade, // Your desired transition // duration: Duration(milliseconds: 400), // Duration of the transition ); if (res != null && res['status'] == true) { _loadProfile(); } }, ), _divider(), _tile( icon: Icons.question_answer, title: "Faq", onTap: () => Get.to( () => FaqView(), // transition: Transition.fade, // or any transition you like // duration: Duration(milliseconds: 400), ), ), _divider(), _tile( icon: Icons.reorder, title: "Your Orders", onTap: () => Get.to( () => const OrdersByStoreScreen(showBackArrow: true), // transition: Transition.fade, // or any transition you prefer // duration: Duration(milliseconds: 400), ), ), // _divider(), ], ), /// PREFERENCES controller.isLoading.value ? Preferences() : _section( title: "Preferences", children: [ _tile( icon: Icons.star_rate, title: "Rate the app in Playstore", onTap: controller.rateApp, ), _divider(), // _tile( // icon: Icons.group_add, // title: "Refer a Friend", // onTap: () => Get.to( // () => const ShowContactsScreen(), // // transition: Transition.fade, // or any style you like // // duration: Duration(milliseconds: 400), // ), // ), ], ), /// SUPPORT controller.isLoading.value ? Preferences() : _section( title: "Support", children: [ _tile( icon: Icons.support_agent, title: "Help & Support", onTap: () => Get.to( () => Help_Support(), // transition: Transition.fade, // simple fade // duration: Duration(milliseconds: 400), ), ), _divider(), _tile( icon: Icons.logout, title: "Logout", isLogout: true, onTap: () { showLogoutDialog(); }, ), ], ), const SizedBox(height: 20), /// LOGOUT // GestureDetector( // onTap: showLogoutDialog, // child: Container( // margin: const EdgeInsets.symmetric(horizontal: 16), // padding: const EdgeInsets.symmetric(vertical: 14), // decoration: BoxDecoration( // color: Colors.white, // borderRadius: BorderRadius.circular(16), // border: Border.all(color: Colors.red, width: 0.4), // ), // child: Center( // child: ReusableTextWidget( // text: "Logout", // color: Colors.red, // fontSize: 16, // fontWeight: FontWeight.w600, // fontFamily: FontConstants.fontFamily, // ), // ), // ), // ), const SizedBox(height: 30), ], ), ), ), ), ); } /// SECTION CARD Widget _section({ required String title, required List children, }) { return Padding( padding: const EdgeInsets.fromLTRB(11, 0, 11, 11), child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(16), border: Border.all( color: Colors.black12, width: 0.20 ), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.03), blurRadius: 2, offset: const Offset(0, 3), ), ], ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.fromLTRB(16, 14, 16, 6), child: ReusableTextWidget( text: title, fontSize: 14, fontWeight: FontWeight.bold, color: Colors.black, fontFamily: FontConstants.fontFamily, ), ), ...children, ], ), ), ); } /// LIST TILE (EXACT STYLE) Widget _tile({ required IconData icon, required String title, required VoidCallback onTap, bool isLogout = false, }) { final Color mainColor = isLogout ? Colors.red : Colors.black45; return ListTile( dense: true, minVerticalPadding: 0, contentPadding: const EdgeInsets.symmetric(horizontal: 12), visualDensity: const VisualDensity(vertical: 0.10), leading: Icon( icon, size: 22, color: mainColor, shadows: [ Shadow( color: Colors.grey.withOpacity(0.2), offset: const Offset(0.30, 0.30), blurRadius: 1, ), ], ), title: ReusableTextWidget( text: title, fontSize: 13, fontWeight: FontWeight.w700, fontFamily: FontConstants.fontFamily, color: isLogout ? Colors.red : Colors.black.withOpacity(0.7), ), // ๐Ÿ‘‡ Arrow ALWAYS normal black trailing: Icon( Icons.arrow_forward_ios, size: 14, weight: 400, color: Colors.black.withOpacity(0.9), ), onTap: onTap, ); } Widget _divider() { return Divider( color: Color(0xFFF6F6F6), thickness: 1.5, height: 0.10, // ); } /// LOGOUT DIALOG (UNCHANGED LOGIC) void showLogoutDialog() { Get.dialog( Dialog( elevation: 0, backgroundColor: Colors.transparent, child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(20), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.15), blurRadius: 20, offset: const Offset(0, 10), ), ], ), padding: const EdgeInsets.all(22), child: Column( mainAxisSize: MainAxisSize.min, children: [ // ๐Ÿ”ด Icon Container Container( height: 64, width: 64, decoration: BoxDecoration( shape: BoxShape.circle, gradient: LinearGradient( colors: [ primaryColor.withOpacity(0.9), primaryColor, ], begin: Alignment.topLeft, end: Alignment.bottomRight, ), ), child: const Icon( Icons.logout_rounded, size: 30, color: Colors.white, ), ), const SizedBox(height: 16), // ๐Ÿ“ Title ReusableTextWidget( text: "Logout", fontSize: 18, fontWeight: FontWeight.w600, fontFamily: FontConstants.fontFamily, color: Colors.black, ), const SizedBox(height: 6), // ๐Ÿงพ Subtitle ReusableTextWidget( text: "Are you sure you want to logout?", fontSize: 14, fontWeight: FontWeight.w400, fontFamily: FontConstants.fontFamily, color: Colors.black54, textAlign: TextAlign.center, ), const SizedBox(height: 24), // ๐Ÿ”˜ Buttons Row( children: [ Expanded( child: OutlinedButton( onPressed: () => Navigator.pop(context), style: OutlinedButton.styleFrom( foregroundColor: primaryColor, side: BorderSide(color: primaryColor), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), padding: const EdgeInsets.symmetric(vertical: 12), ), child: ReusableTextWidget( text: "Cancel", fontFamily: FontConstants.fontFamily, fontWeight: FontWeight.w500, ), ), ), const SizedBox(width: 12), Expanded( child: ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: primaryColor, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), elevation: 4, padding: const EdgeInsets.symmetric(vertical: 12), ), onPressed: () async { final prefs = await SharedPreferences.getInstance(); String fcmToken = prefs.getString('fcmToken') ?? ''; String deviceId = prefs.getString('currentDeviceId') ?? ''; await prefs.clear(); await prefs.setString('fcmToken', fcmToken); await prefs.setString('currentDeviceId', deviceId); Get.deleteAll(); GlobalBinding().dependencies(); Get.offAll(() => Login_view()); }, child: ReusableTextWidget( text: "Logout", fontFamily: FontConstants.fontFamily, color: Colors.white, fontWeight: FontWeight.w600, ), ), ), ], ), ], ), ), ), ); } Widget accountListShimmerSingleBox() { return Container( margin: const EdgeInsets.all(16), padding: const EdgeInsets.symmetric(vertical: 8), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(16), ), child: Column( children: List.generate(4, (index) { return Column( children: [ Padding( padding: const EdgeInsets.symmetric( horizontal: 16, vertical: 14, ), child: Row( children: [ // Leading avatar Shimmer.fromColors( baseColor: Colors.grey.shade300, highlightColor: Colors.grey.shade100, child: Container( height: 44, width: 44, decoration: const BoxDecoration( color: Colors.white, ), ), ), const SizedBox(width: 14), // Title + subtitle Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Shimmer.fromColors( baseColor: Colors.grey.shade300, highlightColor: Colors.grey.shade100, child: Padding( padding: const EdgeInsets.only(right: 18.0), child: Container( height: 14, width: double.infinity, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(6), ), ), ), ), const SizedBox(height: 8), Shimmer.fromColors( baseColor: Colors.grey.shade300, highlightColor: Colors.grey.shade100, child: Container( height: 12, width: 120, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(6), ), ), ), ], ), ), const SizedBox(width: 12), // Trailing arrow shimmer Shimmer.fromColors( baseColor: Colors.grey.shade300, highlightColor: Colors.grey.shade100, child: Container( height: 18, width: 18, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(4), ), ), ), ], ), ), // Divider (except last) if (index != 3) Padding( padding: const EdgeInsets.only(left: 74), child: Divider( height: 1, thickness: 0.8, color: Colors.grey.shade200, ), ), ], ); }), ), ); } Widget Preferences() { return Container( margin: const EdgeInsets.all(16), padding: const EdgeInsets.symmetric(vertical: 8), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(16), ), child: Column( children: List.generate(2, (index) { return Column( children: [ Padding( padding: const EdgeInsets.symmetric( horizontal: 16, vertical: 14, ), child: Row( children: [ // Leading avatar Shimmer.fromColors( baseColor: Colors.grey.shade300, highlightColor: Colors.grey.shade100, child: Container( height: 44, width: 44, decoration: const BoxDecoration( color: Colors.white, ), ), ), const SizedBox(width: 14), // Title + subtitle Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Shimmer.fromColors( baseColor: Colors.grey.shade300, highlightColor: Colors.grey.shade100, child: Padding( padding: const EdgeInsets.only(right: 18.0), child: Container( height: 14, width: double.infinity, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(6), ), ), ), ), const SizedBox(height: 8), Shimmer.fromColors( baseColor: Colors.grey.shade300, highlightColor: Colors.grey.shade100, child: Container( height: 12, width: 120, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(6), ), ), ), ], ), ), const SizedBox(width: 12), // Trailing arrow shimmer Shimmer.fromColors( baseColor: Colors.grey.shade300, highlightColor: Colors.grey.shade100, child: Container( height: 18, width: 18, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(4), ), ), ), ], ), ), // Divider (except last) if (index != 1) Padding( padding: const EdgeInsets.only(left: 74), child: Divider( height: 1, thickness: 0.8, color: Colors.grey.shade200, ), ), ], ); }), ), ); } }