2025-12-03 11:57:05 +05:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import '../providers/user_profile_provider.dart';
|
|
|
|
|
|
|
|
|
|
class EditProfileScreen extends StatefulWidget {
|
|
|
|
|
const EditProfileScreen({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<EditProfileScreen> createState() => _EditProfileScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _EditProfileScreenState extends State<EditProfileScreen> {
|
|
|
|
|
final nameCtrl = TextEditingController();
|
|
|
|
|
final companyCtrl = TextEditingController();
|
|
|
|
|
final emailCtrl = TextEditingController();
|
|
|
|
|
final mobileCtrl = TextEditingController();
|
|
|
|
|
final addressCtrl = TextEditingController();
|
|
|
|
|
final pincodeCtrl = TextEditingController();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2025-12-11 18:36:11 +05:30
|
|
|
final profile =
|
|
|
|
|
Provider.of<UserProfileProvider>(context, listen: false).profile;
|
2025-12-03 11:57:05 +05:30
|
|
|
|
|
|
|
|
nameCtrl.text = profile?.customerName ?? '';
|
|
|
|
|
companyCtrl.text = profile?.companyName ?? '';
|
|
|
|
|
emailCtrl.text = profile?.email ?? '';
|
|
|
|
|
mobileCtrl.text = profile?.mobile ?? '';
|
|
|
|
|
addressCtrl.text = profile?.address ?? '';
|
|
|
|
|
pincodeCtrl.text = profile?.pincode ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _submit() async {
|
2025-12-11 18:36:11 +05:30
|
|
|
final provider = Provider.of<UserProfileProvider>(context, listen: false);
|
2025-12-03 11:57:05 +05:30
|
|
|
|
|
|
|
|
final data = {
|
|
|
|
|
"customer_name": nameCtrl.text,
|
|
|
|
|
"company_name": companyCtrl.text,
|
|
|
|
|
"email": emailCtrl.text,
|
|
|
|
|
"mobile_no": mobileCtrl.text,
|
|
|
|
|
"address": addressCtrl.text,
|
|
|
|
|
"pincode": pincodeCtrl.text,
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-11 18:36:11 +05:30
|
|
|
final success = await provider.sendProfileUpdateRequest(context, data);
|
2025-12-03 11:57:05 +05:30
|
|
|
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
SnackBar(
|
2025-12-11 18:36:11 +05:30
|
|
|
content: Text(
|
|
|
|
|
success
|
2025-12-03 11:57:05 +05:30
|
|
|
? "Request submitted. Wait for admin approval."
|
2025-12-11 18:36:11 +05:30
|
|
|
: "Failed to submit request",
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-12-03 11:57:05 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (success) Navigator.pop(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-12-11 18:36:11 +05:30
|
|
|
final darkBlue = const Color(0xFF003B73);
|
|
|
|
|
final screenWidth = MediaQuery.of(context).size.width;
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
|
gradient: LinearGradient(
|
|
|
|
|
colors: [Color(0xFFB3E5FC), Color(0xFFE1F5FE)],
|
|
|
|
|
begin: Alignment.topCenter,
|
|
|
|
|
end: Alignment.bottomCenter,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
|
body: SafeArea(
|
|
|
|
|
child: LayoutBuilder(
|
|
|
|
|
builder: (context, constraints) {
|
|
|
|
|
double scale = (screenWidth / 390).clamp(0.75, 1.3);
|
|
|
|
|
|
|
|
|
|
return SingleChildScrollView(
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 18 * scale),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
SizedBox(height: 8 * scale),
|
|
|
|
|
|
|
|
|
|
/// BACK BUTTON
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(Icons.arrow_back_ios_new, size: 22 * scale),
|
|
|
|
|
color: Colors.red,
|
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
SizedBox(height: 10 * scale),
|
|
|
|
|
|
|
|
|
|
/// TITLE
|
|
|
|
|
Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
"Edit Profile",
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: darkBlue,
|
|
|
|
|
fontSize: 26 * scale,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
SizedBox(height: 20 * scale),
|
|
|
|
|
|
|
|
|
|
/// RESPONSIVE CENTERED FORM CARD
|
|
|
|
|
Center(
|
|
|
|
|
child: Container(
|
|
|
|
|
width: screenWidth > 650 ? 550 : double.infinity,
|
|
|
|
|
padding: EdgeInsets.all(24 * scale),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.white.withOpacity(0.95),
|
|
|
|
|
borderRadius: BorderRadius.circular(20 * scale),
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: Colors.black12.withOpacity(0.15),
|
|
|
|
|
blurRadius: 18 * scale,
|
|
|
|
|
offset: Offset(0, 6 * scale),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
_buildField("Full Name", nameCtrl, scale),
|
|
|
|
|
_buildField("Company Name", companyCtrl, scale),
|
|
|
|
|
_buildField("Email Address", emailCtrl, scale),
|
|
|
|
|
_buildField("Mobile Number", mobileCtrl, scale),
|
|
|
|
|
_buildField("Address", addressCtrl, scale),
|
|
|
|
|
_buildField("Pincode", pincodeCtrl, scale),
|
|
|
|
|
|
|
|
|
|
SizedBox(height: 25 * scale),
|
|
|
|
|
|
|
|
|
|
/// RESPONSIVE GRADIENT SUBMIT BUTTON
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
height: 50 * scale,
|
|
|
|
|
child: DecoratedBox(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius: BorderRadius.circular(14 * scale),
|
|
|
|
|
gradient: const LinearGradient(
|
|
|
|
|
colors: [
|
|
|
|
|
Color(0xFF0052D4),
|
|
|
|
|
Color(0xFF4364F7),
|
|
|
|
|
Color(0xFF6FB1FC),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: Colors.blueAccent.withOpacity(0.4),
|
|
|
|
|
blurRadius: 10 * scale,
|
|
|
|
|
offset: Offset(0, 4 * scale),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
child: ElevatedButton(
|
|
|
|
|
onPressed: _submit,
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius:
|
|
|
|
|
BorderRadius.circular(14 * scale),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
"Submit Update Request",
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 17 * scale,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
SizedBox(height: 30 * scale),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
2025-12-03 11:57:05 +05:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 18:36:11 +05:30
|
|
|
/// Reusable Responsive TextField Builder
|
|
|
|
|
Widget _buildField(
|
|
|
|
|
String label, TextEditingController ctrl, double scale) {
|
2025-12-03 11:57:05 +05:30
|
|
|
return Padding(
|
2025-12-11 18:36:11 +05:30
|
|
|
padding: EdgeInsets.only(bottom: 18 * scale),
|
|
|
|
|
child: Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius: BorderRadius.circular(16 * scale),
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: Colors.black12.withOpacity(0.06),
|
|
|
|
|
blurRadius: 10 * scale,
|
|
|
|
|
offset: Offset(0, 3 * scale),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: ctrl,
|
|
|
|
|
style: TextStyle(fontSize: 15 * scale),
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
filled: true,
|
|
|
|
|
fillColor: Colors.white,
|
|
|
|
|
labelText: label,
|
|
|
|
|
labelStyle: TextStyle(
|
|
|
|
|
color: const Color(0xFF003B73),
|
|
|
|
|
fontSize: 14 * scale,
|
|
|
|
|
),
|
|
|
|
|
border: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(16 * scale),
|
|
|
|
|
borderSide: BorderSide.none,
|
|
|
|
|
),
|
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(16 * scale),
|
|
|
|
|
borderSide: BorderSide(
|
|
|
|
|
color: const Color(0xFF003B73),
|
|
|
|
|
width: 2 * scale,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-12-03 11:57:05 +05:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|