d01e028dc1
- Changed references from companyProfileData to profileData across multiple profile page views for consistency. - Updated UI elements to display user-specific information such as username, email, role, department, and position. - Modified the profile screen to fetch user profile data instead of company profile data. - Added new string constants for user-related fields in ProfileStrings.
202 lines
7.2 KiB
Dart
202 lines
7.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/svg.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:tm_app/core/routes/app_routes.dart';
|
|
import 'package:tm_app/view_models/profile_view_model.dart';
|
|
|
|
import '../../../core/constants/assets.dart';
|
|
import '../../../core/constants/common_strings.dart';
|
|
import '../../../core/theme/colors.dart';
|
|
import '../../../core/utils/app_toast.dart';
|
|
import '../../../core/utils/size_config.dart';
|
|
import '../../../view_models/auth_view_model.dart';
|
|
import '../../shared/desktop_navigation_widget.dart';
|
|
import '../strings/profile_strings.dart';
|
|
import '../widgets/theme_toggle.dart';
|
|
import '../widgets/title_description.dart';
|
|
|
|
class DesktopProfilePage extends StatefulWidget {
|
|
const DesktopProfilePage({super.key});
|
|
|
|
@override
|
|
State<DesktopProfilePage> createState() => _DesktopProfilePageState();
|
|
}
|
|
|
|
class _DesktopProfilePageState extends State<DesktopProfilePage> {
|
|
late ProfileViewModel viewModel;
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
viewModel = context.read<ProfileViewModel>();
|
|
viewModel.addListener(_profileListener);
|
|
}
|
|
|
|
void _profileListener() {
|
|
if (viewModel.errorMessage != null) {
|
|
AppToast.error(context, viewModel.errorMessage!);
|
|
}
|
|
if (viewModel.loggedOut) {
|
|
context.read<AuthViewModel>().clearAuthFlow();
|
|
Router.neglect(context, () => const LoginScreenRoute().go(context));
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
viewModel.removeListener(_profileListener);
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.backgroundColor,
|
|
body: Column(
|
|
children: [
|
|
const DesktopNavigationWidget(
|
|
currentIndex: 4, // Tenders index
|
|
),
|
|
Consumer<ProfileViewModel>(
|
|
builder: (context, viewModel, child) {
|
|
if (viewModel.isLoading) {
|
|
return const Expanded(
|
|
child: Center(
|
|
child: CircularProgressIndicator(
|
|
color: AppColors.secondary50,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
if (viewModel.errorMessage != null) {
|
|
return Expanded(
|
|
child: Center(child: Text(viewModel.errorMessage!)),
|
|
);
|
|
}
|
|
|
|
if (viewModel.profileData == null) {
|
|
return const Expanded(
|
|
child: Center(child: Text(CommonStrings.noData)),
|
|
);
|
|
}
|
|
|
|
return Expanded(
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
SizedBox(
|
|
width: 740,
|
|
child: Column(
|
|
children: [
|
|
SizedBox(height: 36.0.h()),
|
|
TitleDescription(
|
|
title: ProfileStrings.username,
|
|
description:
|
|
viewModel.profileData!.username ?? '',
|
|
),
|
|
TitleDescription(
|
|
title: ProfileStrings.email,
|
|
description: viewModel.profileData!.email ?? '',
|
|
),
|
|
TitleDescription(
|
|
title: ProfileStrings.role,
|
|
description: viewModel.profileData!.role ?? '',
|
|
),
|
|
TitleDescription(
|
|
title: ProfileStrings.department,
|
|
description:
|
|
viewModel.profileData!.department ?? '',
|
|
),
|
|
TitleDescription(
|
|
title: ProfileStrings.position,
|
|
description:
|
|
viewModel.profileData!.position ?? '',
|
|
),
|
|
SizedBox(height: 24.0.h()),
|
|
// Theme Toggle
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: Text(
|
|
ProfileStrings.settings,
|
|
style: TextStyle(
|
|
fontSize: 20.0.sp(),
|
|
fontWeight: FontWeight.w600,
|
|
color: AppColors.grey70,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 36.0.h()),
|
|
_themeChangeRow(),
|
|
SizedBox(height: 24.0.h()),
|
|
Divider(
|
|
color: AppColors.dividerColor,
|
|
thickness: 1,
|
|
),
|
|
SizedBox(height: 24.0.h()),
|
|
// Spacer(),
|
|
Align(
|
|
alignment: AlignmentDirectional.centerEnd,
|
|
child: InkWell(
|
|
onTap: () => viewModel.logout(),
|
|
borderRadius: BorderRadius.circular(100),
|
|
child: Container(
|
|
width: 156,
|
|
height: 56.0.h(),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.primary20,
|
|
borderRadius: BorderRadius.circular(100),
|
|
),
|
|
alignment: Alignment.center,
|
|
child: Text(
|
|
ProfileStrings.logout,
|
|
style: TextStyle(
|
|
fontSize: 14.0.sp(),
|
|
fontWeight: FontWeight.w500,
|
|
color: AppColors.primaryColor,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _themeChangeRow() {
|
|
return Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 8.0.w()),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
ProfileStrings.appTheme,
|
|
style: TextStyle(
|
|
fontSize: 16.0.sp(),
|
|
fontWeight: FontWeight.w400,
|
|
color: AppColors.grey70,
|
|
),
|
|
),
|
|
const Spacer(),
|
|
SvgPicture.asset(AssetsManager.sun),
|
|
SizedBox(width: 12.0.w()),
|
|
SizedBox(
|
|
width: 52.0.w(),
|
|
height: 32.0.h(),
|
|
child: const ThemeToggle(),
|
|
),
|
|
SizedBox(width: 12.0.w()),
|
|
SvgPicture.asset(AssetsManager.moon),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|