update info
This commit is contained in:
@@ -18,6 +18,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:worker/core/constants/ui_constants.dart';
|
||||
import 'package:worker/core/theme/colors.dart';
|
||||
import 'package:worker/features/account/presentation/providers/user_info_provider.dart' hide UserInfo;
|
||||
|
||||
/// Profile Edit Page
|
||||
///
|
||||
@@ -27,47 +28,128 @@ class ProfileEditPage extends HookConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
// Watch user info from API
|
||||
final userInfoAsync = ref.watch(userInfoProvider);
|
||||
|
||||
// Form key for validation
|
||||
final formKey = useMemoized(() => GlobalKey<FormState>());
|
||||
|
||||
// Image picker
|
||||
final selectedImage = useState<File?>(null);
|
||||
|
||||
// Form controllers
|
||||
final nameController = useTextEditingController(text: 'Hoàng Minh Hiệp');
|
||||
final phoneController = useTextEditingController(text: '0347302911');
|
||||
final emailController = useTextEditingController(
|
||||
text: 'hoanghiep@example.com',
|
||||
);
|
||||
final birthDateController = useTextEditingController(text: '15/03/1985');
|
||||
final idNumberController = useTextEditingController(text: '123456789012');
|
||||
final taxIdController = useTextEditingController(text: '0359837618');
|
||||
final companyController = useTextEditingController(
|
||||
text: 'Công ty TNHH Xây dựng ABC',
|
||||
);
|
||||
final addressController = useTextEditingController(
|
||||
text: '123 Man Thiện, Thủ Đức, Hồ Chí Minh',
|
||||
);
|
||||
final experienceController = useTextEditingController(text: '10');
|
||||
|
||||
// Dropdown values
|
||||
final selectedGender = useState<String>('male');
|
||||
final selectedPosition = useState<String>('contractor');
|
||||
|
||||
// Has unsaved changes
|
||||
final hasChanges = useState<bool>(false);
|
||||
|
||||
return PopScope(
|
||||
canPop: !hasChanges.value,
|
||||
onPopInvokedWithResult: (didPop, result) async {
|
||||
if (didPop) return;
|
||||
return userInfoAsync.when(
|
||||
loading: () => Scaffold(
|
||||
backgroundColor: const Color(0xFFF4F6F8),
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
title: const Text(
|
||||
'Thông tin cá nhân',
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
centerTitle: false,
|
||||
),
|
||||
body: const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(color: AppColors.primaryBlue),
|
||||
SizedBox(height: AppSpacing.md),
|
||||
Text(
|
||||
'Đang tải thông tin...',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
error: (error, stack) => Scaffold(
|
||||
backgroundColor: const Color(0xFFF4F6F8),
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const FaIcon(FontAwesomeIcons.arrowLeft, color: Colors.black, size: 20),
|
||||
onPressed: () => context.pop(),
|
||||
),
|
||||
title: const Text(
|
||||
'Thông tin cá nhân',
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
centerTitle: false,
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const FaIcon(
|
||||
FontAwesomeIcons.circleExclamation,
|
||||
size: 64,
|
||||
color: AppColors.danger,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
const Text(
|
||||
'Không thể tải thông tin người dùng',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => ref.read(userInfoProvider.notifier).refresh(),
|
||||
icon: const FaIcon(FontAwesomeIcons.arrowsRotate, size: 16),
|
||||
label: const Text('Thử lại'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.primaryBlue,
|
||||
foregroundColor: AppColors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
data: (userInfo) {
|
||||
// Form controllers populated with user data
|
||||
final nameController = useTextEditingController(text: userInfo.fullName);
|
||||
final phoneController = useTextEditingController(text: userInfo.phoneNumber ?? '');
|
||||
final emailController = useTextEditingController(text: userInfo.email ?? '');
|
||||
final birthDateController = useTextEditingController(text: ''); // TODO: Add birthdate to API
|
||||
final idNumberController = useTextEditingController(text: userInfo.cccd ?? '');
|
||||
final taxIdController = useTextEditingController(text: userInfo.taxId ?? '');
|
||||
final companyController = useTextEditingController(text: userInfo.companyName ?? '');
|
||||
final addressController = useTextEditingController(text: userInfo.address ?? '');
|
||||
final experienceController = useTextEditingController(text: ''); // TODO: Add experience to API
|
||||
|
||||
final shouldPop = await _showUnsavedChangesDialog(context);
|
||||
if (shouldPop == true && context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
// Dropdown values
|
||||
final selectedGender = useState<String>('male'); // TODO: Add gender to API
|
||||
final selectedPosition = useState<String>('contractor'); // TODO: Map from userInfo.role
|
||||
|
||||
return PopScope(
|
||||
canPop: !hasChanges.value,
|
||||
onPopInvokedWithResult: (didPop, result) async {
|
||||
if (didPop) return;
|
||||
|
||||
final shouldPop = await _showUnsavedChangesDialog(context);
|
||||
if (shouldPop == true && context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: const Color(0xFFF4F6F8),
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
@@ -107,7 +189,12 @@ class ProfileEditPage extends HookConsumerWidget {
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
|
||||
// Profile Avatar Section
|
||||
_buildAvatarSection(context, selectedImage),
|
||||
_buildAvatarSection(
|
||||
context,
|
||||
selectedImage,
|
||||
userInfo.initials,
|
||||
userInfo.avatarUrl,
|
||||
),
|
||||
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
|
||||
@@ -276,7 +363,9 @@ class ProfileEditPage extends HookConsumerWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -284,70 +373,83 @@ class ProfileEditPage extends HookConsumerWidget {
|
||||
Widget _buildAvatarSection(
|
||||
BuildContext context,
|
||||
ValueNotifier<File?> selectedImage,
|
||||
String initials,
|
||||
String? avatarUrl,
|
||||
) {
|
||||
return Center(
|
||||
child: Stack(
|
||||
children: [
|
||||
// Avatar
|
||||
Container(
|
||||
width: 100,
|
||||
height: 100,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColors.primaryBlue,
|
||||
image: selectedImage.value != null
|
||||
? DecorationImage(
|
||||
image: FileImage(selectedImage.value!),
|
||||
fit: BoxFit.cover,
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: AppSpacing.sm),
|
||||
child: Center(
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
// Avatar
|
||||
Container(
|
||||
width: 100,
|
||||
height: 100,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: AppColors.primaryBlue,
|
||||
image: selectedImage.value != null
|
||||
? DecorationImage(
|
||||
image: FileImage(selectedImage.value!),
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
: avatarUrl != null
|
||||
? DecorationImage(
|
||||
image: NetworkImage(avatarUrl),
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
child: selectedImage.value == null && avatarUrl == null
|
||||
? Center(
|
||||
child: Text(
|
||||
initials,
|
||||
style: const TextStyle(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
child: selectedImage.value == null
|
||||
? const Center(
|
||||
child: Text(
|
||||
'HMH',
|
||||
style: TextStyle(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
|
||||
// Edit Button
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
await _pickImage(context, selectedImage);
|
||||
},
|
||||
child: Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primaryBlue,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white, width: 2),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.1),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
// Edit Button
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
await _pickImage(context, selectedImage);
|
||||
},
|
||||
child: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primaryBlue,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white, width: 3),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.15),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Center(
|
||||
child: FaIcon(
|
||||
FontAwesomeIcons.camera,
|
||||
size: 16,
|
||||
color: Colors.white,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const FaIcon(
|
||||
FontAwesomeIcons.camera,
|
||||
size: 14,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -473,7 +575,18 @@ class ProfileEditPage extends HookConsumerWidget {
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
suffixIcon: const FaIcon(FontAwesomeIcons.calendar, size: 18),
|
||||
suffixIcon: const Padding(
|
||||
padding: EdgeInsets.only(right: 12),
|
||||
child: FaIcon(
|
||||
FontAwesomeIcons.calendar,
|
||||
size: 20,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
),
|
||||
suffixIconConstraints: const BoxConstraints(
|
||||
minWidth: 48,
|
||||
minHeight: 48,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.input),
|
||||
borderSide: const BorderSide(color: Color(0xFFE2E8F0)),
|
||||
@@ -517,6 +630,14 @@ class ProfileEditPage extends HookConsumerWidget {
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: value,
|
||||
onChanged: onChanged,
|
||||
icon: const Padding(
|
||||
padding: EdgeInsets.only(right: 12),
|
||||
child: FaIcon(
|
||||
FontAwesomeIcons.chevronDown,
|
||||
size: 16,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: const Color(0xFFF8FAFC),
|
||||
|
||||
Reference in New Issue
Block a user