237 lines
7.5 KiB
Dart
237 lines
7.5 KiB
Dart
import 'dart:convert';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:socialbuddy_mobile/core/constants/colors.dart';
|
|
import 'package:socialbuddy_mobile/features/auth/providers/auth_provider.dart';
|
|
import 'package:socialbuddy_mobile/features/auth/screens/login_screen.dart';
|
|
|
|
class ProfileScreen extends StatefulWidget {
|
|
const ProfileScreen({super.key});
|
|
|
|
@override
|
|
State<ProfileScreen> createState() => _ProfileScreenState();
|
|
}
|
|
|
|
class _ProfileScreenState extends State<ProfileScreen> {
|
|
Map<String, dynamic>? _userData;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadUserData();
|
|
}
|
|
|
|
Future<void> _loadUserData() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final userJson = prefs.getString('user_details');
|
|
if (userJson != null) {
|
|
setState(() {
|
|
_userData = jsonDecode(userJson);
|
|
});
|
|
}
|
|
}
|
|
|
|
Future<void> _handleLogout() async {
|
|
final confirm = await showDialog<bool>(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
backgroundColor: AppColors.cardBg,
|
|
title: Text("Log Out", style: GoogleFonts.nunito(color: Colors.white, fontWeight: FontWeight.bold)),
|
|
content: Text("Are you sure you want to log out?", style: GoogleFonts.nunito(color: Colors.white70)),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, false),
|
|
child: Text("Cancel", style: GoogleFonts.nunito(color: Colors.white38)),
|
|
),
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, true),
|
|
child: Text("Log Out", style: GoogleFonts.nunito(color: AppColors.danger, fontWeight: FontWeight.bold)),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
if (confirm == true) {
|
|
if (mounted) {
|
|
await Provider.of<AuthProvider>(context, listen: false).logout();
|
|
if (mounted) {
|
|
Navigator.of(context).pushAndRemoveUntil(
|
|
MaterialPageRoute(builder: (context) => const LoginScreen()),
|
|
(route) => false,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.darkBg,
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(
|
|
children: [
|
|
const SizedBox(height: 20),
|
|
// Profile Header
|
|
Center(
|
|
child: Stack(
|
|
children: [
|
|
Container(
|
|
width: 100,
|
|
height: 100,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
gradient: const LinearGradient(
|
|
colors: [Color(0xFF2B65EC), Color(0xFFD946EF)],
|
|
),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.blue.withOpacity(0.3),
|
|
blurRadius: 20,
|
|
spreadRadius: 2,
|
|
),
|
|
],
|
|
),
|
|
child: const Center(
|
|
child: Icon(Icons.person, size: 50, color: Colors.white),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
_userData?['name'] ?? "Social Buddy User",
|
|
style: GoogleFonts.nunito(
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
Text(
|
|
_userData?['email'] ?? "user@example.com",
|
|
style: GoogleFonts.nunito(
|
|
fontSize: 16,
|
|
color: Colors.white38,
|
|
),
|
|
),
|
|
const SizedBox(height: 32),
|
|
|
|
// Stats Row or Info
|
|
Container(
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.cardBg,
|
|
borderRadius: BorderRadius.circular(20),
|
|
border: Border.all(color: Colors.white.withOpacity(0.05)),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
_buildStatItem("Role", _userData?['role']?.toString().toUpperCase() ?? "CUSTOMER"),
|
|
Container(width: 1, height: 40, color: Colors.white10),
|
|
_buildStatItem("Status", "ACTIVE"),
|
|
],
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 32),
|
|
|
|
// Menu Items
|
|
_buildMenuItem(Icons.person_outline, "Account Settings", () {}),
|
|
_buildMenuItem(Icons.notifications_none_rounded, "Notifications", () {}),
|
|
_buildMenuItem(Icons.security_rounded, "Privacy & Security", () {}),
|
|
_buildMenuItem(Icons.help_outline_rounded, "Help Center", () {}),
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
// Logout Button
|
|
SizedBox(
|
|
width: double.infinity,
|
|
height: 56,
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppColors.danger.withOpacity(0.1),
|
|
side: const BorderSide(color: AppColors.danger, width: 1),
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
|
elevation: 0,
|
|
),
|
|
onPressed: _handleLogout,
|
|
child: Text(
|
|
"Log Out",
|
|
style: GoogleFonts.nunito(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
color: AppColors.danger,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildStatItem(String label, String value) {
|
|
return Column(
|
|
children: [
|
|
Text(
|
|
value,
|
|
style: GoogleFonts.nunito(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
label,
|
|
style: GoogleFonts.nunito(
|
|
fontSize: 12,
|
|
color: Colors.white38,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildMenuItem(IconData icon, String title, VoidCallback onTap) {
|
|
return Container(
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
borderRadius: BorderRadius.circular(16),
|
|
child: Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.cardBg,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: Colors.white.withOpacity(0.05)),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Icon(icon, color: Colors.blueAccent, size: 24),
|
|
const SizedBox(width: 16),
|
|
Expanded(
|
|
child: Text(
|
|
title,
|
|
style: GoogleFonts.nunito(
|
|
fontSize: 16,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
const Icon(Icons.arrow_forward_ios, color: Colors.white24, size: 16),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|