import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:pulse/Screens/authScreen/LoginScreen.dart'; import 'package:pulse/Screens/home_screen.dart'; import 'package:pulse/utils/AppColors.dart'; import 'package:pulse/utils/SharedpreferencesService.dart'; class ProfileScreen extends StatefulWidget { final String sessionId; final String staffId; final String csrfToken; final String userName; final String userEmail; final String profileImageUrl; const ProfileScreen({ Key? key, required this.sessionId, required this.staffId, required this.csrfToken, this.userName = "User Name", this.userEmail = "user@example.com", this.profileImageUrl = "", }) : super(key: key); @override State createState() => _ProfileScreenState(); } class _ProfileScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppColors.primaryColor, body: SafeArea( child: Column( children: [ // Custom App Bar _buildCustomAppBar(), Expanded( child: SingleChildScrollView( padding: const EdgeInsets.all(24), child: Column( children: [ // Profile Header Section _buildProfileHeader(), const SizedBox(height: 40), // Profile Information Cards _buildProfileInfoCards(), const SizedBox(height: 40), ], ), ), ), // Logout Button _buildLogoutButton(), ], ), ), ); } Widget _buildCustomAppBar() { return Container( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), decoration: BoxDecoration( color: AppColors.primaryColor, boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.1), blurRadius: 8, offset: const Offset(0, 2), ), ], ), child: Row( children: [ Container( decoration: BoxDecoration( shape: BoxShape.circle, color: Colors.white.withOpacity(0.1), ), child: IconButton( icon: const Icon(Icons.arrow_back, color: Colors.white), onPressed: () => Navigator.pop(context), ), ), const SizedBox(width: 16), const Text( "Profile", style: TextStyle( fontSize: 20, fontFamily: 'JakartaRegular', fontWeight: FontWeight.w700, color: Colors.white, ), ), ], ), ); } Widget _buildProfileHeader() { return Column( children: [ // Profile Picture with Decorative Ring Stack( alignment: Alignment.center, children: [ // Outer Ring Container( width: 148, height: 148, decoration: BoxDecoration( borderRadius: BorderRadius.circular(28), shape: BoxShape.rectangle, gradient: LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [ Colors.white.withOpacity(0.3), Colors.white.withOpacity(0.1), ], ), ), ), // Profile Image Container Container( width: 140, height: 140, decoration: BoxDecoration( borderRadius: BorderRadius.circular(25), color: Colors.white.withOpacity(0.1), border: Border.all( color: Colors.white.withOpacity(0.4), width: 3, ), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.3), blurRadius: 15, offset: const Offset(0, 6), ), ], ), child: widget.profileImageUrl.isNotEmpty ? ClipRRect( borderRadius: BorderRadius.circular(22), child: CachedNetworkImage( imageUrl: widget.profileImageUrl, width: 140, height: 140, fit: BoxFit.cover, placeholder: (context, url) => Container( decoration: BoxDecoration( color: AppColors.cardColor, borderRadius: BorderRadius.circular(22), ), child: const Center( child: CircularProgressIndicator( strokeWidth: 2, valueColor: AlwaysStoppedAnimation(Colors.white), ), ), ), errorWidget: (context, url, error) => Container( decoration: BoxDecoration( color: AppColors.cardColor, borderRadius: BorderRadius.circular(22), ), child: const Center( child: Icon(Icons.person, color: Colors.white, size: 50), ), ), ), ) : Center( child: Icon( Icons.person, size: 60, color: Colors.white.withOpacity(0.7), ), ), ), ], ), const SizedBox(height: 24), // User Name with Welcome Text Column( children: [ Text( "Welcome Back,", style: TextStyle( fontSize: 16, fontFamily: 'JakartaRegular', color: Colors.white.withOpacity(0.8), ), ), const SizedBox(height: 4), Text( widget.userName, style: const TextStyle( fontSize: 24, fontFamily: 'JakartaRegular', fontWeight: FontWeight.w700, color: Colors.white, ), textAlign: TextAlign.center, ), ], ), ], ); } Widget _buildProfileInfoCards() { return Column( children: [ // Personal Information Card Container( width: double.infinity, padding: const EdgeInsets.all(20), decoration: BoxDecoration( color: Colors.white.withOpacity(0.08), borderRadius: BorderRadius.circular(20), border: Border.all( color: Colors.white.withOpacity(0.1), ), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // Section Title Row( children: [ Container( padding: const EdgeInsets.all(6), decoration: BoxDecoration( color: Colors.white.withOpacity(0.1), shape: BoxShape.circle, ), child: const Icon( Icons.info, color: Colors.white, size: 18, ), ), const SizedBox(width: 12), const Text( "Personal Information", style: TextStyle( fontSize: 16, fontFamily: 'JakartaRegular', fontWeight: FontWeight.w600, color: Colors.white, ), ), ], ), const SizedBox(height: 20), // Information Items _buildInfoItem( icon: Icons.person_outline, label: "Full Name", value: widget.userName, ), const SizedBox(height: 16), _buildInfoItem( icon: Icons.email_outlined, label: "Email Address", value: widget.userEmail, ), const SizedBox(height: 16), // _buildInfoItem( // icon: Icons.badge_outlined, // label: "Staff ID", // value: widget.staffId, // ), ], ), ), ], ); } Widget _buildInfoItem({ required IconData icon, required String label, required String value, }) { return Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( padding: const EdgeInsets.all(8), decoration: BoxDecoration( color: Colors.white.withOpacity(0.05), borderRadius: BorderRadius.circular(10), ), child: Icon( icon, color: Colors.white.withOpacity(0.7), size: 20, ), ), const SizedBox(width: 16), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( label, style: TextStyle( fontSize: 12, fontFamily: 'JakartaRegular', color: Colors.white.withOpacity(0.6), ), ), const SizedBox(height: 4), Text( value, style: const TextStyle( fontSize: 16, fontFamily: 'JakartaRegular', fontWeight: FontWeight.w500, color: Colors.white, ), ), ], ), ), ], ); } Widget _buildLogoutButton() { return Container( width: double.infinity, padding: const EdgeInsets.all(24), decoration: BoxDecoration( color: AppColors.primaryColor, border: Border( top: BorderSide( color: Colors.white.withOpacity(0.1), ), ), ), child: ElevatedButton( onPressed: () { _showLogoutConfirmationDialog(); }, style: ElevatedButton.styleFrom( backgroundColor: Colors.redAccent.withOpacity(0.9), foregroundColor: Colors.white, padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 24), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(15), side: BorderSide( color: Colors.white.withOpacity(0.2), ), ), elevation: 0, ), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon( Icons.logout_rounded, color: Colors.white.withOpacity(0.9), size: 22, ), const SizedBox(width: 12), Text( "Logout", style: TextStyle( fontSize: 16, fontFamily: 'JakartaRegular', fontWeight: FontWeight.w600, color: Colors.white.withOpacity(0.9), ), ), ], ), ), ); } void _showLogoutConfirmationDialog() { showDialog( context: context, builder: (BuildContext context) { return Dialog( backgroundColor: Colors.transparent, child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(20), ), child: Padding( padding: const EdgeInsets.all(24), child: Column( mainAxisSize: MainAxisSize.min, children: [ // Icon Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: const Color(0xFFFEF2F2), shape: BoxShape.circle, ), child: const Icon( Icons.logout_rounded, color: Color(0xFFEF4444), size: 32, ), ), const SizedBox(height: 16), // Title const Text( "Logout Confirmation", style: TextStyle( fontSize: 18, fontFamily: 'JakartaRegular', fontWeight: FontWeight.w700, color: Colors.black, ), ), const SizedBox(height: 8), // Message Text( "Are you sure you want to logout?", style: TextStyle( fontSize: 14, fontFamily: 'JakartaRegular', color: Colors.grey.shade600, ), textAlign: TextAlign.center, ), const SizedBox(height: 24), // Buttons Row( children: [ Expanded( child: OutlinedButton( onPressed: () => Navigator.pop(context), style: OutlinedButton.styleFrom( foregroundColor: Colors.grey.shade700, side: BorderSide(color: Colors.grey.shade400), padding: const EdgeInsets.symmetric(vertical: 12), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), ), child: const Text("Cancel"), ), ), const SizedBox(width: 12), Expanded( child: ElevatedButton( onPressed: () async { Navigator.pop(context); // Close dialog first await _performLogout(); }, style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFFEF4444), foregroundColor: Colors.white, padding: const EdgeInsets.symmetric(vertical: 12), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), ), child: const Text("Logout"), ), ), ], ), ], ), ), ), ); }, ); } Future _performLogout() async { // Show loading indicator showDialog( context: context, barrierDismissible: false, builder: (context) => Dialog( backgroundColor: Colors.transparent, child: Container( padding: const EdgeInsets.all(24), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(15), ), child: const Column( mainAxisSize: MainAxisSize.min, children: [ CircularProgressIndicator( valueColor: AlwaysStoppedAnimation(AppColors.primaryColor), ), SizedBox(height: 16), Text( "Logging out...", style: TextStyle( fontFamily: 'JakartaRegular', fontWeight: FontWeight.w500, ), ), ], ), ), ), ); try { // Your logout logic here final prefs = SharedPreferencesService.instance; await prefs.remove("email"); await prefs.remove("password"); await prefs.remove("sessionId"); await prefs.remove("staffId"); // Navigate to LoginScreen and remove all previous routes if (mounted) { Navigator.pushAndRemoveUntil( context, MaterialPageRoute(builder: (_) => const LoginScreen()), (route) => false, ); } } catch (e) { if (mounted) { Navigator.pop(context); // Close loading indicator ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Logout failed: $e'), backgroundColor: Colors.red, ), ); } } } }