last 16-10-2025

This commit is contained in:
mageshwaran committed 2025-10-16 11:21:52 +05:30
commit 7546b7348c
269 files changed
+36404

No files matched your search

@@ -0,0 +1,456 @@
import 'dart:io';
import 'package:bookmywages/consts_widgets/app_assets.dart';
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/consts_widgets/comman_button.dart';
import 'package:bookmywages/consts_widgets/comman_textformfiled.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:bookmywages/viewmodel/consts_api.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:image_picker/image_picker.dart';
class EditProfile extends StatefulWidget {
const EditProfile({super.key});
@override
State<EditProfile> createState() => _EditProfileState();
}
class _EditProfileState extends State<EditProfile> {
File? _image;
final ImagePicker _picker = ImagePicker();
final TextEditingController nameController = TextEditingController();
final TextEditingController numberController = TextEditingController();
final TextEditingController emailController = TextEditingController();
final TextEditingController addressController = TextEditingController();
bool _isProfileDataInitialized = false;
Future<void> _pickImage() async {
final pickedFile = await _picker.pickImage(source: ImageSource.gallery);
if (pickedFile != null) {
setState(() {
_image = File(pickedFile.path);
});
}
}
// Helper method to validate and construct image URL
String? _getValidImageUrl(String? imageUrl) {
if (imageUrl == null || imageUrl.isEmpty) {
return null;
}
// Check if URL is complete (has a filename)
if (imageUrl.endsWith('/') || imageUrl.endsWith('/images/')) {
return null;
}
// Ensure URL is properly formatted
if (!imageUrl.startsWith('http')) {
return null;
}
return imageUrl;
}
// Helper widget for safe network image loading
Widget _buildNetworkImage(String? imageUrl, {BoxFit fit = BoxFit.cover}) {
final validUrl = _getValidImageUrl(imageUrl);
if (validUrl == null) {
return Image.asset(AppAssets.profile, fit: fit);
}
return Image.network(
validUrl,
fit: fit,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!
: null,
),
);
},
errorBuilder: (context, error, stackTrace) {
print('Error loading image: $error');
return Image.asset(AppAssets.profile, fit: fit);
},
);
}
// Helper method for CircleAvatar image provider
ImageProvider _getAvatarImageProvider(String? imageUrl) {
if (_image != null) {
return FileImage(_image!);
}
final validUrl = _getValidImageUrl(imageUrl);
if (validUrl != null) {
return NetworkImage(validUrl);
}
return const AssetImage(AppAssets.profile);
}
final TextStyle gilroyTextStyle = const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 20,
height: 1.45,
letterSpacing: 0.01,
);
@override
void dispose() {
nameController.dispose();
numberController.dispose();
emailController.dispose();
addressController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Scaffold(
backgroundColor: AppColors.secondprimary,
resizeToAvoidBottomInset: false,
body: SafeArea(
child: LayoutBuilder(
builder: (context, constraints) {
return SingleChildScrollView(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: constraints.maxHeight),
child: IntrinsicHeight(
child: Column(
children: [
Stack(
children: [
SizedBox(
width: double.infinity,
height: height * 0.4,
child: Consumer(
builder: (context, ref, _) {
final profileData = ref.watch(
profilegetuserProvider,
);
return profileData.when(
data: (profiles) {
final profile = profiles.isNotEmpty
? profiles[0]
: null;
if (profile != null &&
!_isProfileDataInitialized) {
WidgetsBinding.instance
.addPostFrameCallback((_) {
setState(() {
nameController.text =
profile.name ?? '';
numberController.text =
profile.number ?? '';
emailController.text =
profile.email ?? '';
addressController.text =
profile.address ?? '';
_isProfileDataInitialized = true;
});
});
}
return _image == null
? _buildNetworkImage(
profile?.profilePic1,
)
: Image.file(
_image!,
fit: BoxFit.cover,
);
},
loading: () => const Center(
child: CircularProgressIndicator(),
),
error: (error, _) => Center(
child: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
const Icon(Icons.error, size: 50),
Text('Error loading profile: $error'),
],
),
),
);
},
),
),
Positioned(
bottom: 0,
child: CustomPaint(
size: Size(width, height * 0.4),
painter: RightToLeftFullWidthTrianglePainter(),
),
),
Positioned(
bottom: height * 0.03,
left: width / 2 - 170,
child: Consumer(
builder: (context, ref, _) {
final profileData = ref.watch(
profilegetuserProvider,
);
return profileData.when(
data: (profiles) {
final profile = profiles.isNotEmpty
? profiles[0]
: null;
return CircleAvatar(
radius: 68,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 65,
backgroundImage:
_getAvatarImageProvider(
profile?.profilePic1,
),
onBackgroundImageError:
(error, stackTrace) {
print(
'Avatar image error: $error',
);
},
),
);
},
loading: () => const CircleAvatar(
radius: 68,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 65,
child: CircularProgressIndicator(),
),
),
error: (error, _) => const CircleAvatar(
radius: 68,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 65,
backgroundImage: AssetImage(
AppAssets.menu,
),
),
),
);
},
),
),
Positioned(
bottom: height * 0.08,
left: width / 2 - 20,
child: Consumer(
builder: (context, ref, _) {
final profileData = ref.watch(
profilegetuserProvider,
);
return profileData.when(
data: (profiles) {
final profile = profiles.isNotEmpty
? profiles[0]
: null;
if (profile == null) {
return Text(
'No Profile Data',
style: gilroyTextStyle,
);
}
return Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
profile.name ?? 'No Name',
style: gilroyTextStyle,
),
IconButton(
onPressed: _pickImage,
icon: const Icon(Icons.edit),
),
],
),
Row(
children: [
const Icon(
Icons.location_city,
size: 20,
),
const SizedBox(width: 4),
Text(
profile.address ??
'No address available',
style: const TextStyle(
fontSize: 12,
),
),
],
),
],
);
},
loading: () =>
const CircularProgressIndicator(),
error: (error, _) => Text(
'Error: $error',
style: gilroyTextStyle,
),
);
},
),
),
],
),
const SizedBox(height: 30),
Padding(
padding: EdgeInsets.symmetric(horizontal: width * 0.05),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Name", style: gilroyTextStyle),
const SizedBox(height: 15),
CommonTextFormField(
hintText: "Enter your name",
controller: nameController,
),
const SizedBox(height: 30),
Text("Mobile Number", style: gilroyTextStyle),
const SizedBox(height: 15),
CommonTextFormField(
hintText: "Enter your mobile number",
keyboardType: TextInputType.phone,
controller: numberController,
),
const SizedBox(height: 30),
Text("Address", style: gilroyTextStyle),
const SizedBox(height: 15),
CommonTextFormField(
hintText: "Enter your address",
controller: addressController,
),
const SizedBox(height: 30),
Text("Email", style: gilroyTextStyle),
const SizedBox(height: 15),
CommonTextFormField(
hintText: "Enter your email",
keyboardType: TextInputType.emailAddress,
controller: emailController,
),
const SizedBox(height: 30),
Center(
child: Consumer(
builder: (context, ref, _) {
return CommanButton(
width: width * 0.6,
text: "Save",
textStyle: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 23,
height: 1.0,
letterSpacing: 0.01,
color: AppColors.secondprimary,
),
onPressed: () async {
try {
final repo = ref.read(
profileupdateRepositoryProvider,
);
await repo.updateProfile(
url: ConstsApi.upadateprofile,
name: nameController.text,
number: numberController.text,
email: emailController.text,
address: addressController.text,
imageFile: _image,
);
if (mounted) {
Fluttertoast.showToast(
msg: "Profile updated successfully",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.green,
textColor: Colors.white,
);
ref.refresh(profilegetuserProvider);
Future.delayed(
const Duration(milliseconds: 1500),
() {
if (mounted) {
Navigator.of(context).pop();
}
},
);
}
} catch (e) {
if (mounted) {
Fluttertoast.showToast(
msg: "Error updating profile: $e",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
);
}
}
},
);
},
),
),
const SizedBox(height: 30),
],
),
),
],
),
),
),
);
},
),
),
);
}
}
class RightToLeftFullWidthTrianglePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()..color = Colors.white;
final path = Path();
path.moveTo(size.width, 0);
path.lineTo(size.width, size.height);
path.lineTo(0, size.height);
path.close();
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}
@@ -0,0 +1,421 @@
import 'package:bookmywages/consts_widgets/app_assets.dart';
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fluttertoast/fluttertoast.dart';
class ProfileChangepass extends ConsumerStatefulWidget {
const ProfileChangepass({super.key});
@override
ConsumerState<ProfileChangepass> createState() => _ProfileChangepassState();
}
class _ProfileChangepassState extends ConsumerState<ProfileChangepass> {
final TextEditingController _newPasswordController = TextEditingController();
final TextEditingController _confirmPasswordController =
TextEditingController();
final _formKey = GlobalKey<FormState>();
bool _obscureNewPassword = true;
bool _obscureConfirmPassword = true;
String? _newPasswordError;
String? _confirmPasswordError;
@override
void dispose() {
_newPasswordController.dispose();
_confirmPasswordController.dispose();
super.dispose();
}
Future<void> _submitForm() async {
FocusScope.of(context).unfocus();
// Reset errors
setState(() {
_newPasswordError = null;
_confirmPasswordError = null;
});
if (_formKey.currentState!.validate()) {
try {
final success = await ref.read(
changepasswordProvider(_newPasswordController.text).future,
);
if (success && mounted) {
Fluttertoast.showToast(
msg: "Password changed successfully",
backgroundColor: Colors.green,
textColor: Colors.white,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
Navigator.pop(context);
} else {
Fluttertoast.showToast(
msg: "Failed to change password",
backgroundColor: Colors.red,
textColor: Colors.white,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
}
} catch (e) {
if (mounted) {
Fluttertoast.showToast(
msg: "Error: ${e.toString()}",
backgroundColor: Colors.red,
textColor: Colors.white,
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
);
}
}
}
}
String? _validateNewPassword(String? value) {
if (value == null || value.isEmpty) {
setState(() {
_newPasswordError = "Please enter a password";
});
return "";
}
if (value.length < 6) {
// Fixed: was 4, should be 6 as per error message
setState(() {
_newPasswordError = "Password must be at least 6 characters";
});
return "";
}
setState(() {
_newPasswordError = null;
});
return null;
}
String? _validateConfirmPassword(String? value) {
if (value == null || value.isEmpty) {
setState(() {
_confirmPasswordError = "Please confirm your password";
});
return "";
}
if (value != _newPasswordController.text) {
setState(() {
_confirmPasswordError = "Passwords don't match";
});
return "";
}
setState(() {
_confirmPasswordError = null;
});
return null;
}
@override
Widget build(BuildContext context) {
final keyboardHeight = MediaQuery.of(context).viewInsets.bottom;
final isKeyboardVisible = keyboardHeight > 0;
final screenHeight = MediaQuery.of(context).size.height;
return Scaffold(
backgroundColor: AppColors.secondprimary,
resizeToAvoidBottomInset: false, // Keep false to prevent white space
body: GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Container(
height: screenHeight, // Fixed height
color: AppColors.secondprimary,
child: SafeArea(
child: Column(
children: [
// Header with back button
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
GestureDetector(
onTap: () => Navigator.pop(context),
child: const Icon(
Icons.arrow_back_ios_new,
size: 20,
color: Colors.black,
),
),
const Expanded(
child: Center(
child: Text(
'Change Password',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
),
),
const SizedBox(width: 20),
],
),
),
// Scrollable content with proper height calculation
Expanded(
child: SingleChildScrollView(
physics: const ClampingScrollPhysics(),
padding: EdgeInsets.only(
left: 16.0,
right: 16.0,
bottom: isKeyboardVisible ? keyboardHeight + 16 : 16.0,
),
child: Column(
children: [
// Show smaller image when keyboard is visible, normal size when not
if (!isKeyboardVisible) ...[
Image.asset(
AppAssets.changepass,
width: MediaQuery.of(context).size.width * 0.7,
height: MediaQuery.of(context).size.height * 0.3,
fit: BoxFit.contain,
),
const SizedBox(height: 16),
] else ...[
// Smaller image when keyboard is open
Image.asset(
AppAssets.changepass,
width: MediaQuery.of(context).size.width * 0.4,
height: screenHeight * 0.12, // Even smaller height
fit: BoxFit.contain,
),
const SizedBox(height: 8),
],
// Form to change password
Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Create Password",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontSize: 20,
fontWeight: FontWeight.w700,
color: Colors.black87,
height: 18.68 / 20,
letterSpacing: 0.5,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 53,
decoration: BoxDecoration(
color: const Color(0xFFFDFFFF),
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: const Color(0xFF8C8A8A),
),
),
child: TextFormField(
controller: _newPasswordController,
obscureText: _obscureNewPassword,
decoration: InputDecoration(
hintText: "Enter new password",
contentPadding:
const EdgeInsets.symmetric(
horizontal: 16,
vertical: 10,
),
border: InputBorder.none,
hintStyle: const TextStyle(
fontFamily: 'Martel',
fontWeight: FontWeight.w700,
fontSize: 14,
height: 29 / 14,
letterSpacing: -0.5,
color: Color(0xFF757576),
),
suffixIcon: IconButton(
icon: Icon(
_obscureNewPassword
? Icons.visibility_off
: Icons.visibility,
color: Colors.grey,
),
onPressed: () {
setState(() {
_obscureNewPassword =
!_obscureNewPassword;
});
},
),
),
validator: _validateNewPassword,
),
),
SizedBox(
height: _newPasswordError != null ? 28 : 0,
child:
_newPasswordError != null
? Padding(
padding: const EdgeInsets.only(
top: 8.0,
left: 16.0,
),
child: Text(
_newPasswordError!,
style: const TextStyle(
color: Colors.red,
fontSize: 12,
),
),
)
: null,
),
],
),
const SizedBox(height: 20),
const Text(
"Confirm Password",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontSize: 20,
fontWeight: FontWeight.w700,
color: Colors.black87,
height: 18.68 / 20,
letterSpacing: 0.5,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 20),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 53,
decoration: BoxDecoration(
color: const Color(0xFFFDFFFF),
borderRadius: BorderRadius.circular(15),
border: Border.all(
color: const Color(0xFF8C8A8A),
),
),
child: TextFormField(
controller: _confirmPasswordController,
obscureText: _obscureConfirmPassword,
decoration: InputDecoration(
hintText: "Confirm your password",
contentPadding:
const EdgeInsets.symmetric(
horizontal: 16,
vertical: 10,
),
border: InputBorder.none,
hintStyle: const TextStyle(
fontFamily: 'Martel',
fontWeight: FontWeight.w700,
fontSize: 14,
height: 29 / 14,
letterSpacing: -0.5,
color: Color(0xFF757576),
),
suffixIcon: IconButton(
icon: Icon(
_obscureConfirmPassword
? Icons.visibility_off
: Icons.visibility,
color: Colors.grey,
),
onPressed: () {
setState(() {
_obscureConfirmPassword =
!_obscureConfirmPassword;
});
},
),
),
validator: _validateConfirmPassword,
),
),
SizedBox(
height:
_confirmPasswordError != null ? 28 : 0,
child:
_confirmPasswordError != null
? Padding(
padding: const EdgeInsets.only(
top: 8.0,
left: 16.0,
),
child: Text(
_confirmPasswordError!,
style: const TextStyle(
color: Colors.red,
fontSize: 12,
),
),
)
: null,
),
],
),
const SizedBox(height: 20),
Center(
child: SizedBox(
width: 299,
height: 61.71,
child: ElevatedButton(
onPressed: _submitForm,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0066FF),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
34.77,
),
),
elevation: 0,
),
child: const Text(
"Save",
style: TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 28.76,
height: 1.0,
letterSpacing: 0.01,
),
),
),
),
),
// Add some bottom spacing
SizedBox(height: isKeyboardVisible ? 16 : 30),
],
),
),
],
),
),
),
],
),
),
),
),
);
}
}
@@ -0,0 +1,668 @@
import 'dart:ui';
import 'package:bookmywages/consts_widgets/app_assets.dart';
import 'package:bookmywages/consts_widgets/app_colors.dart';
import 'package:bookmywages/routers/consts_router.dart';
import 'package:bookmywages/viewmodel/api_controller.dart';
import 'package:bookmywages/viewmodel/consts_api.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ProfileMainPage extends StatefulWidget {
const ProfileMainPage({super.key});
@override
State<ProfileMainPage> createState() => _ProfileMainPageState();
}
class _ProfileMainPageState extends State<ProfileMainPage> {
File? _image;
final ImagePicker _picker = ImagePicker();
bool _isProfileDataInitialized = false;
bool _isUploading = false;
// Modified _pickImage method with automatic API upload using existing repository
Future<void> _pickImage() async {
try {
final pickedFile = await _picker.pickImage(source: ImageSource.gallery);
if (pickedFile != null) {
setState(() {
_image = File(pickedFile.path);
_isUploading = true;
});
// Automatically upload to API using existing repository
await _uploadImageToAPI(File(pickedFile.path));
}
} catch (e) {
print('Error picking image: $e');
_showErrorToast('Failed to pick image: $e');
}
}
// Upload image using existing ProfileupdateRepository
Future<void> _uploadImageToAPI(File imageFile) async {
try {
// Get current profile data
final profileData = ProviderScope.containerOf(
context,
).read(profilegetuserProvider);
await profileData.when(
data: (profiles) async {
if (profiles.isNotEmpty) {
final profile = profiles[0];
// Get the repository
final repository = ProviderScope.containerOf(
context,
).read(profileupdateRepositoryProvider);
// Update profile with new image and existing data
await repository.updateProfile(
url: ConstsApi.upadateprofile, // Use your existing API constant
name: profile.name,
number: profile.number,
email: profile.email,
address: profile.address ?? '',
imageFile: imageFile,
);
// Refresh profile data to get updated image URL
ProviderScope.containerOf(context).refresh(profilegetuserProvider);
ProviderScope.containerOf(
context,
).refresh(profileupdateuserProvider);
_showSuccessToast('Profile picture updated successfully!');
// Clear local image since it's now uploaded
setState(() {
_image = null;
});
} else {
_showErrorToast('No profile data available');
setState(() {
_image = null;
});
}
},
loading: () async {
_showErrorToast('Profile data is still loading');
setState(() {
_image = null;
});
},
error: (error, _) async {
_showErrorToast('Error getting profile data: $error');
setState(() {
_image = null;
});
},
);
} catch (e) {
print('Error uploading image: $e');
_showErrorToast('Upload failed: $e');
setState(() {
_image = null;
});
} finally {
setState(() {
_isUploading = false;
});
}
}
// Helper methods for showing toasts
void _showSuccessToast(String message) {
Fluttertoast.showToast(
msg: message,
backgroundColor: Colors.green,
textColor: Colors.white,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
}
void _showErrorToast(String message) {
Fluttertoast.showToast(
msg: message,
backgroundColor: Colors.red,
textColor: Colors.white,
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
);
}
// Helper method to validate and construct image URL
String? _getValidImageUrl(String? imageUrl) {
if (imageUrl == null || imageUrl.isEmpty) {
return null;
}
// Check if URL is complete (has a filename)
if (imageUrl.endsWith('/') || imageUrl.endsWith('/images/')) {
return null;
}
// Ensure URL is properly formatted
if (!imageUrl.startsWith('http')) {
return null;
}
return imageUrl;
}
// Helper widget for safe network image loading
Widget _buildNetworkImage(String? imageUrl, {BoxFit fit = BoxFit.cover}) {
final validUrl = _getValidImageUrl(imageUrl);
if (validUrl == null) {
return Image.asset(AppAssets.profile, fit: fit);
}
return Image.network(
validUrl,
fit: fit,
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) return child;
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!
: null,
),
);
},
errorBuilder: (context, error, stackTrace) {
print('Error loading image: $error');
return Image.asset(AppAssets.profile, fit: fit);
},
);
}
// Helper method for CircleAvatar image provider
ImageProvider _getAvatarImageProvider(String? imageUrl) {
if (_image != null) {
return FileImage(_image!);
}
final validUrl = _getValidImageUrl(imageUrl);
if (validUrl != null) {
return NetworkImage(validUrl);
}
return const AssetImage(AppAssets.profile);
}
final TextStyle gilroyTextStyle = const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 20,
height: 1.45,
letterSpacing: 0.01,
);
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Scaffold(
backgroundColor: AppColors.secondprimary,
body: SafeArea(
child: Column(
children: [
Flexible(
flex: 1,
child: Stack(
children: [
SizedBox(
width: double.infinity,
height: height * 0.4,
child: Consumer(
builder: (context, ref, _) {
final profileData = ref.watch(profilegetuserProvider);
return profileData.when(
data: (profiles) {
final profile = profiles.isNotEmpty
? profiles[0]
: null;
if (profile != null && !_isProfileDataInitialized) {
WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
profile.address ?? '';
_isProfileDataInitialized = true;
});
});
}
return _image == null
? _buildNetworkImage(profile?.profilePic1)
: Image.file(_image!, fit: BoxFit.cover);
},
loading: () =>
const Center(child: CircularProgressIndicator()),
error: (error, _) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error, size: 50),
Text('Error loading profile: $error'),
],
),
),
);
},
),
),
Positioned(
bottom: 0,
child: CustomPaint(
size: Size(width, height * 0.4),
painter: RightToLeftFullWidthTrianglePainter(),
),
),
Positioned(
bottom: height * 0.03,
left: width / 2 - 170,
child: Consumer(
builder: (context, ref, _) {
final profileData = ref.watch(profilegetuserProvider);
return profileData.when(
data: (profiles) {
final profile = profiles.isNotEmpty
? profiles[0]
: null;
return Stack(
alignment: Alignment.center,
children: [
CircleAvatar(
radius: 68,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 65,
backgroundImage: _getAvatarImageProvider(
profile?.profilePic1,
),
onBackgroundImageError:
(error, stackTrace) {
print('Avatar image error: $error');
},
),
),
// Show upload progress indicator
if (_isUploading)
Container(
width: 136,
height: 136,
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5),
shape: BoxShape.circle,
),
child: const Center(
child: CircularProgressIndicator(
color: Colors.white,
),
),
),
],
);
},
loading: () => const CircleAvatar(
radius: 68,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 65,
child: CircularProgressIndicator(),
),
),
error: (error, _) => const CircleAvatar(
radius: 68,
backgroundColor: Colors.white,
child: CircleAvatar(
radius: 65,
backgroundImage: AssetImage(AppAssets.menu),
),
),
);
},
),
),
Positioned(
bottom: height * 0.08,
left: width / 2 - 20,
child: Consumer(
builder: (context, ref, _) {
final profileData = ref.watch(profilegetuserProvider);
return profileData.when(
data: (profiles) {
final profile = profiles.isNotEmpty
? profiles[0]
: null;
if (profile == null) {
return Text(
'No Profile Data',
style: gilroyTextStyle,
);
}
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
profile.name ?? 'No Name',
style: gilroyTextStyle,
),
IconButton(
onPressed: _isUploading
? null
: _pickImage,
icon: _isUploading
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(
strokeWidth: 2,
),
)
: const Icon(Icons.edit),
),
],
),
Row(
children: [
const Icon(Icons.location_city, size: 20),
const SizedBox(width: 4),
Text(
profile.address ?? 'No address available',
style: const TextStyle(fontSize: 12),
),
],
),
],
);
},
loading: () => const CircularProgressIndicator(),
error: (error, _) =>
Text('Error: $error', style: gilroyTextStyle),
);
},
),
),
],
),
),
const SizedBox(height: 30),
Expanded(
flex: 1,
child: ListView(
shrinkWrap: false,
physics: const NeverScrollableScrollPhysics(),
children: [
_buildMenuItem(Icons.person, 'My Profile'),
_buildMenuItem(Icons.lock, 'Change Password'),
_buildMenuItem(Icons.notifications, 'Notification'),
_buildMenuItem(Icons.description, 'Terms and Conditions'),
_buildMenuItem(Icons.logout, 'Sign out'),
],
),
),
],
),
),
);
}
Widget _buildMenuItem(IconData icon, String title) {
return ListTile(
leading: Icon(
icon,
size: 23.000513076782227,
color: const Color(0xFF3E3E3F),
),
title: Text(
title,
style: const TextStyle(
fontFamily: 'Gilroy-Bold',
fontWeight: FontWeight.w700,
fontSize: 18,
height: 1.0,
letterSpacing: 0.2,
color: Color(0xFF3E3E3F),
),
),
trailing: const Icon(Icons.arrow_forward_ios_rounded),
onTap: () async {
try {
if (title == 'My Profile') {
await Get.toNamed(RouterConts.editprofile);
} else if (title == 'Change Password') {
await Get.toNamed(RouterConts.changepassword);
} else if (title == 'Sign out') {
_showSignOutDialog();
} else if (title == 'Terms and Conditions') {
_showTermsAndConditionsDialog(); // Removed ref parameter
}
} catch (e) {
print('Navigation error: $e');
if (mounted) {
Fluttertoast.showToast(
msg: 'Navigation error: $e',
backgroundColor: Colors.red,
textColor: Colors.white,
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
);
}
}
},
);
}
void _showSignOutDialog() {
if (!mounted) return;
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Sign Out'),
content: const Text('Are you sure you want to sign out?'),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('Cancel'),
),
TextButton(
onPressed: () async {
Navigator.of(context).pop();
final prefs = await SharedPreferences.getInstance();
await prefs.remove('userId');
await prefs.remove('vendor_id');
await prefs.remove('data');
if (context.mounted) {
// context.go(
// RouterConts.loginpage,
// ); // or use pushReplacement if needed
}
},
child: const Text('Sign Out'),
),
],
);
},
);
}
void _showTermsAndConditionsDialog() {
// Removed WidgetRef ref parameter
if (!mounted) return;
showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
child: Dialog(
backgroundColor: Colors.transparent,
insetPadding: const EdgeInsets.all(20),
child: Center(
child: Consumer(
builder: (context, ref, _) {
final termsAsync = ref.watch(termsAndConditionsProvider);
return termsAsync.when(
data: (terms) => Container(
width: 389,
height: 547,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: const Color(0xFF959595),
width: 1,
),
),
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Center(
child: Text(
"Terms & Condition",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
),
const SizedBox(height: 12),
Expanded(
child: ScrollbarTheme(
data: ScrollbarThemeData(
thumbColor: WidgetStateProperty.all(
AppColors.primary,
),
trackColor: WidgetStateProperty.all(
Colors.transparent,
),
trackBorderColor: WidgetStateProperty.all(
Colors.transparent,
),
thickness: WidgetStateProperty.all(13),
radius: const Radius.circular(19),
thumbVisibility: WidgetStateProperty.all(true),
),
child: Scrollbar(
thumbVisibility: true,
interactive: true,
thickness: 13,
radius: const Radius.circular(19),
child: ListView(
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
terms.data,
style: const TextStyle(
color: Colors.black,
),
),
const SizedBox(height: 20),
Center(
child: SizedBox(
width: 228,
height: 51.82,
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(
0xFF0066FF,
),
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(
22.95,
),
),
),
child: const Text(
"OK",
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 18.87,
height: 23.59 / 18.87,
letterSpacing: -0.59,
color: Colors.white,
),
),
),
),
),
],
),
],
),
),
),
),
],
),
),
loading: () =>
const Center(child: CircularProgressIndicator()),
error: (e, _) => Container(
padding: const EdgeInsets.all(16),
child: Text(
"Error: ${e.toString()}",
style: const TextStyle(color: Colors.red),
),
),
);
},
),
),
),
);
},
);
}
}
class RightToLeftFullWidthTrianglePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()..color = Colors.white;
final path = Path();
path.moveTo(size.width, 0); // top right corner
path.lineTo(size.width, size.height); // bottom right corner
path.lineTo(0, size.height); // bottom left (tip)
path.close();
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}