update info
This commit is contained in:
@@ -8,14 +8,20 @@
|
||||
/// - Logout button
|
||||
library;
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:worker/core/constants/ui_constants.dart';
|
||||
import 'package:worker/core/database/hive_initializer.dart';
|
||||
import 'package:worker/core/database/models/enums.dart';
|
||||
import 'package:worker/core/router/app_router.dart';
|
||||
import 'package:worker/core/theme/colors.dart';
|
||||
import 'package:worker/features/account/domain/entities/user_info.dart'
|
||||
as domain;
|
||||
import 'package:worker/features/account/presentation/providers/user_info_provider.dart'
|
||||
hide UserInfo;
|
||||
import 'package:worker/features/account/presentation/widgets/account_menu_item.dart';
|
||||
import 'package:worker/features/auth/presentation/providers/auth_provider.dart';
|
||||
|
||||
@@ -27,30 +33,98 @@ class AccountPage extends ConsumerWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final userInfoAsync = ref.watch(userInfoProvider);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF4F6F8),
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
spacing: AppSpacing.md,
|
||||
children: [
|
||||
// Simple Header
|
||||
_buildHeader(),
|
||||
child: userInfoAsync.when(
|
||||
loading: () => 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) => 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 tài khoản',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Text(
|
||||
error.toString(),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
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) => RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
await ref.read(userInfoProvider.notifier).refresh();
|
||||
},
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: Column(
|
||||
spacing: AppSpacing.md,
|
||||
children: [
|
||||
// Simple Header
|
||||
_buildHeader(),
|
||||
|
||||
// User Profile Card
|
||||
_buildProfileCard(context),
|
||||
// User Profile Card with API data
|
||||
_buildProfileCard(context, userInfo),
|
||||
|
||||
// Account Menu Section
|
||||
_buildAccountMenu(context),
|
||||
// Account Menu Section
|
||||
_buildAccountMenu(context),
|
||||
|
||||
// Support Section
|
||||
_buildSupportSection(context),
|
||||
// Support Section
|
||||
_buildSupportSection(context),
|
||||
|
||||
// Logout Button
|
||||
_buildLogoutButton(context, ref),
|
||||
// Logout Button
|
||||
_buildLogoutButton(context, ref),
|
||||
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
],
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -84,7 +158,10 @@ class AccountPage extends ConsumerWidget {
|
||||
}
|
||||
|
||||
/// Build user profile card with avatar and info
|
||||
Widget _buildProfileCard(BuildContext context) {
|
||||
Widget _buildProfileCard(
|
||||
BuildContext context,
|
||||
domain.UserInfo userInfo,
|
||||
) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: AppSpacing.md),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
@@ -101,54 +178,109 @@ class AccountPage extends ConsumerWidget {
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// Avatar with gradient background
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
colors: [Color(0xFF005B9A), Color(0xFF38B6FF)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
),
|
||||
child: const Center(
|
||||
child: Text(
|
||||
'LQ',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.w700,
|
||||
// Avatar with API data or gradient fallback
|
||||
userInfo.avatarUrl != null
|
||||
? ClipOval(
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: userInfo.avatarUrl!,
|
||||
width: 80,
|
||||
height: 80,
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
colors: [Color(0xFF005B9A), Color(0xFF38B6FF)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
),
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
errorWidget: (context, url, error) => Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
colors: [Color(0xFF005B9A), Color(0xFF38B6FF)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
userInfo.initials,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
colors: [Color(0xFF005B9A), Color(0xFF38B6FF)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
userInfo.initials,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
|
||||
// User info
|
||||
// User info from API
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: AppSpacing.xs,
|
||||
children: [
|
||||
const Text(
|
||||
'La Nguyen Quynh',
|
||||
style: TextStyle(
|
||||
Text(
|
||||
userInfo.fullName,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.grey900,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const Text(
|
||||
'Kiến trúc sư · Hạng Diamond',
|
||||
style: TextStyle(fontSize: 13, color: AppColors.grey500),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const Text(
|
||||
'0983 441 099',
|
||||
style: TextStyle(fontSize: 13, color: AppColors.primaryBlue),
|
||||
Text(
|
||||
'${_getRoleDisplayName(userInfo.role)} · Hạng ${userInfo.tierDisplayName}',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
),
|
||||
if (userInfo.phoneNumber != null)
|
||||
Text(
|
||||
userInfo.phoneNumber!,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColors.primaryBlue,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -472,4 +604,18 @@ class AccountPage extends ConsumerWidget {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Get Vietnamese display name for user role
|
||||
String _getRoleDisplayName(UserRole role) {
|
||||
switch (role) {
|
||||
case UserRole.customer:
|
||||
return 'Khách hàng';
|
||||
case UserRole.distributor:
|
||||
return 'Đại lý phân phối';
|
||||
case UserRole.admin:
|
||||
return 'Quản trị viên';
|
||||
case UserRole.staff:
|
||||
return 'Nhân viên';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user