Your changes
This commit is contained in:
@@ -9,13 +9,11 @@ import 'login_screen.dart';
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
const SettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
State<SettingsScreen> createState() => _SettingsScreenState();
|
||||
}
|
||||
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -27,32 +25,33 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
|
||||
final profileProvider =
|
||||
Provider.of<UserProfileProvider>(context, listen: false);
|
||||
profileProvider.init(context);
|
||||
|
||||
await profileProvider.loadProfile(context);
|
||||
final profile = Provider.of<UserProfileProvider>(context, listen: false);
|
||||
profile.init(context);
|
||||
await profile.loadProfile(context);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _pickImage() async {
|
||||
final picked = await ImagePicker().pickImage(
|
||||
source: ImageSource.gallery,
|
||||
imageQuality: 80,
|
||||
);
|
||||
|
||||
if (picked != null) {
|
||||
final file = File(picked.path);
|
||||
final profileProvider =
|
||||
Provider.of<UserProfileProvider>(context, listen: false);
|
||||
|
||||
profileProvider.init(context);
|
||||
|
||||
final success = await profileProvider.updateProfileImage(context, file);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(success ? "Profile updated" : "Failed to update")),
|
||||
try {
|
||||
final picked = await ImagePicker().pickImage(
|
||||
source: ImageSource.gallery,
|
||||
imageQuality: 80,
|
||||
);
|
||||
if (picked != null) {
|
||||
final file = File(picked.path);
|
||||
final profile = Provider.of<UserProfileProvider>(context, listen: false);
|
||||
profile.init(context);
|
||||
final ok = await profile.updateProfileImage(context, file);
|
||||
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(ok ? "Profile updated" : "Failed to update")),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text("Error: $e")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,131 +61,309 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
final confirm = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
|
||||
title: const Text("Logout"),
|
||||
content: const Text("Are you sure you want to logout?"),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context, false), child: const Text("Cancel")),
|
||||
TextButton(
|
||||
child: const Text("Cancel"),
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
),
|
||||
TextButton(
|
||||
child: const Text("Logout", style: TextStyle(color: Colors.red)),
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
),
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: const Text("Logout", style: TextStyle(color: Colors.red))),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirm == true) {
|
||||
await auth.logout(context);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const LoginScreen()),
|
||||
(route) => false,
|
||||
(r) => false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final profileProvider = Provider.of<UserProfileProvider>(context);
|
||||
|
||||
if (profileProvider.loading || profileProvider.profile == null) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
final p = profileProvider.profile!;
|
||||
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(18),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// ------------------ PROFILE IMAGE ------------------
|
||||
Center(
|
||||
child: GestureDetector(
|
||||
onTap: _pickImage,
|
||||
child: CircleAvatar(
|
||||
radius: 55,
|
||||
backgroundImage: p.profileImage != null
|
||||
? NetworkImage(p.profileImage!)
|
||||
: null,
|
||||
child: p.profileImage == null
|
||||
? const Icon(Icons.person, size: 55)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 25),
|
||||
|
||||
// ------------------ PROFILE INFO ------------------
|
||||
_infoRow("Customer ID", p.customerId),
|
||||
_infoRow("Name", p.customerName),
|
||||
_infoRow("Company", p.companyName),
|
||||
_infoRow("Email", p.email),
|
||||
_infoRow("Mobile", p.mobile),
|
||||
_infoRow("Address", p.address ?? "Not provided"),
|
||||
_infoRow("Pincode", p.pincode ?? "Not provided"),
|
||||
_infoRow("Status", p.status ?? "N/A"),
|
||||
_infoRow("Customer Type", p.customerType ?? "N/A"),
|
||||
|
||||
const SizedBox(height: 40),
|
||||
|
||||
Center(
|
||||
child: ElevatedButton(
|
||||
child: const Text("Edit Profile"),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const EditProfileScreen()),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// ------------------ LOGOUT BUTTON ------------------
|
||||
Center(
|
||||
child: ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.red,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 14),
|
||||
),
|
||||
icon: const Icon(Icons.logout, color: Colors.white),
|
||||
label: const Text(
|
||||
"Logout",
|
||||
style: TextStyle(color: Colors.white, fontSize: 16),
|
||||
),
|
||||
onPressed: _logout,
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
|
||||
|
||||
const SizedBox(height: 30),
|
||||
],
|
||||
),
|
||||
// ------------------------- REUSABLE FIELD ROW -------------------------
|
||||
Widget _fieldRow(IconData icon, String label, String value, double scale) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 12 * scale),
|
||||
child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Icon(icon, size: 26 * scale, color: Colors.blueGrey.shade700),
|
||||
SizedBox(width: 14 * scale),
|
||||
Expanded(
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text(label,
|
||||
style: TextStyle(
|
||||
fontSize: 14 * scale,
|
||||
color: Colors.grey[700],
|
||||
fontWeight: FontWeight.w700)),
|
||||
SizedBox(height: 4 * scale),
|
||||
Text(value,
|
||||
style: TextStyle(
|
||||
fontSize: 16 * scale, fontWeight: FontWeight.bold)),
|
||||
]),
|
||||
)
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _infoRow(String title, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 14),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.grey)),
|
||||
const SizedBox(height: 4),
|
||||
Text(value, style: const TextStyle(fontSize: 16)),
|
||||
],
|
||||
// ------------------------- INFO TILE -------------------------
|
||||
Widget _infoTile(IconData icon, String title, String value, double scale) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(icon, size: 26 * scale, color: Colors.orange.shade800),
|
||||
SizedBox(width: 14 * scale),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title,
|
||||
style: TextStyle(
|
||||
fontSize: 13 * scale,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.black54)),
|
||||
SizedBox(height: 4 * scale),
|
||||
Text(value,
|
||||
style: TextStyle(
|
||||
fontSize: 17 * scale, fontWeight: FontWeight.bold))
|
||||
]),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final profile = Provider.of<UserProfileProvider>(context);
|
||||
|
||||
if (profile.loading || profile.profile == null) {
|
||||
return const Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
|
||||
// ----------- RESPONSIVE SCALE -----------
|
||||
final width = MediaQuery.of(context).size.width;
|
||||
final scale = (width / 390).clamp(0.80, 1.25);
|
||||
|
||||
final p = profile.profile!;
|
||||
final img = p.profileImage;
|
||||
final name = p.customerName ?? "Unknown";
|
||||
final email = p.email ?? "Not provided";
|
||||
final status = p.status ?? "Active";
|
||||
final cid = p.customerId ?? "—";
|
||||
final company = p.companyName ?? "—";
|
||||
final type = p.customerType ?? "—";
|
||||
final mobile = p.mobile ?? "—";
|
||||
final address = p.address ?? "Not provided";
|
||||
final pincode = p.pincode ?? "—";
|
||||
final isPartner = type.toLowerCase().contains("partner");
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFE9F2FF),
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: EdgeInsets.all(18 * scale),
|
||||
child: Column(
|
||||
children: [
|
||||
// -------------------- PROFILE SECTION --------------------
|
||||
Center(
|
||||
child: Column(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: _pickImage,
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 64 * scale,
|
||||
backgroundColor: Colors.grey[200],
|
||||
backgroundImage:
|
||||
img != null ? NetworkImage(img) : null,
|
||||
child: img == null
|
||||
? Icon(Icons.person,
|
||||
size: 70 * scale, color: Colors.grey[600])
|
||||
: null,
|
||||
),
|
||||
|
||||
// ------------------ FIXED STATUS BADGE ------------------
|
||||
Positioned(
|
||||
bottom: 8 * scale,
|
||||
right: 8 * scale,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 12 * scale,
|
||||
vertical: 6 * scale),
|
||||
decoration: BoxDecoration(
|
||||
color: status.toLowerCase() == 'active'
|
||||
? Colors.green
|
||||
: Colors.orange,
|
||||
borderRadius: BorderRadius.circular(20 * scale),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.2),
|
||||
blurRadius: 8 * scale)
|
||||
],
|
||||
),
|
||||
child: Text(
|
||||
status,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 13 * scale,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 14 * scale),
|
||||
Text(name,
|
||||
style: TextStyle(
|
||||
fontSize: 20 * scale,
|
||||
fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 6 * scale),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.email,
|
||||
size: 18 * scale, color: Colors.blueGrey),
|
||||
SizedBox(width: 8 * scale),
|
||||
Text(email,
|
||||
style: TextStyle(
|
||||
fontSize: 14 * scale,
|
||||
color: Colors.grey[700])),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 26 * scale),
|
||||
|
||||
// ---------------------- YELLOW SUMMARY CARD ----------------------
|
||||
Container(
|
||||
padding: EdgeInsets.all(18 * scale),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [Color(0xFFFFF8A3), Color(0xFFFFE275)],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16 * scale),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.orange.withOpacity(0.25),
|
||||
blurRadius: 14 * scale,
|
||||
offset: Offset(0, 8 * scale))
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_infoTile(Icons.badge, "Customer ID", cid, scale),
|
||||
Divider(height: 30 * scale),
|
||||
_infoTile(Icons.business, "Company Name", company, scale),
|
||||
Divider(height: 30 * scale),
|
||||
_infoTile(Icons.category, "Customer Type", type, scale),
|
||||
SizedBox(height: 20 * scale),
|
||||
|
||||
if (isPartner)
|
||||
Container(
|
||||
padding: EdgeInsets.all(14 * scale),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(14 * scale),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.08),
|
||||
blurRadius: 10 * scale)
|
||||
],
|
||||
),
|
||||
child: Row(children: [
|
||||
Icon(Icons.workspace_premium,
|
||||
size: 32 * scale, color: Colors.amber[800]),
|
||||
SizedBox(width: 12 * scale),
|
||||
Text("Partner",
|
||||
style: TextStyle(
|
||||
fontSize: 16 * scale,
|
||||
fontWeight: FontWeight.bold)),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
),
|
||||
|
||||
SizedBox(height: 24 * scale),
|
||||
|
||||
// ---------------------- DETAILS CARD ----------------------
|
||||
Container(
|
||||
padding: EdgeInsets.all(16 * scale),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(14 * scale),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.06),
|
||||
blurRadius: 12 * scale)
|
||||
]),
|
||||
child: Column(
|
||||
children: [
|
||||
_fieldRow(Icons.phone_android, "Mobile", mobile, scale),
|
||||
const Divider(),
|
||||
_fieldRow(Icons.location_on, "Address", address, scale),
|
||||
const Divider(),
|
||||
_fieldRow(Icons.local_post_office, "Pincode", pincode, scale),
|
||||
SizedBox(height: 20 * scale),
|
||||
|
||||
Row(children: [
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) =>
|
||||
const EditProfileScreen()));
|
||||
},
|
||||
icon: Icon(Icons.edit,
|
||||
color: Colors.white, size: 18 * scale),
|
||||
label: Text("Edit Profile",
|
||||
style: TextStyle(
|
||||
color: Colors.white, fontSize: 14 * scale)),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.blue[700],
|
||||
padding:
|
||||
EdgeInsets.symmetric(vertical: 14 * scale),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12 * scale)),
|
||||
),
|
||||
)),
|
||||
SizedBox(width: 12 * scale),
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: _logout,
|
||||
icon: Icon(Icons.logout,
|
||||
size: 18 * scale, color: Colors.white),
|
||||
label: Text("Logout",
|
||||
style: TextStyle(
|
||||
color: Colors.white, fontSize: 14 * scale)),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.red[600],
|
||||
padding:
|
||||
EdgeInsets.symmetric(vertical: 14 * scale),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12 * scale)),
|
||||
),
|
||||
)),
|
||||
])
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 30 * scale),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user