a5b01ffac4
- Added a new field for companies in the ProfileData model to store associated company information. - Updated JSON serialization methods to handle the new companies field. - Modified profile page views to display the user's full name and company name, replacing previous role and department fields for improved clarity. - Introduced new string constants for full name and phone in ProfileStrings.
191 lines
6.3 KiB
Dart
191 lines
6.3 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 'package:tm_app/views/profile/widgets/theme_toggle.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/tender_app_bar.dart';
|
|
import '../strings/profile_strings.dart';
|
|
import '../widgets/title_description.dart';
|
|
|
|
class MobileProfilePage extends StatefulWidget {
|
|
const MobileProfilePage({super.key});
|
|
|
|
@override
|
|
State<MobileProfilePage> createState() => _MobileProfilePageState();
|
|
}
|
|
|
|
class _MobileProfilePageState extends State<MobileProfilePage> {
|
|
late ProfileViewModel viewModel;
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
viewModel = context.read<ProfileViewModel>();
|
|
viewModel.addListener(_profileListener);
|
|
// Load notification info saved in SharedPreferences
|
|
}
|
|
|
|
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,
|
|
appBar: tenderMobileAppBar(title: ProfileStrings.profileTitle),
|
|
body: Consumer<ProfileViewModel>(
|
|
builder: (context, viewModel, child) {
|
|
if (viewModel.isLoading) {
|
|
return const Center(
|
|
child: CircularProgressIndicator(color: AppColors.secondary50),
|
|
);
|
|
}
|
|
|
|
if (viewModel.errorMessage != null) {
|
|
return Center(child: Text(viewModel.errorMessage!));
|
|
}
|
|
|
|
if (viewModel.profileData == null) {
|
|
return const Center(child: Text(CommonStrings.noData));
|
|
}
|
|
|
|
return SafeArea(
|
|
child: Padding(
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: 24.0.w(),
|
|
vertical: 16.0.h(),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
SizedBox(height: 36.0.h()),
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: Text(
|
|
'Last Notification',
|
|
style: TextStyle(
|
|
fontSize: 18.0.sp(),
|
|
fontWeight: FontWeight.w600,
|
|
color: AppColors.grey70,
|
|
),
|
|
),
|
|
),
|
|
|
|
SizedBox(height: 24.0.h()),
|
|
TitleDescription(
|
|
title: ProfileStrings.fullname,
|
|
description: viewModel.profileData!.fullName ?? '',
|
|
),
|
|
TitleDescription(
|
|
title: ProfileStrings.username,
|
|
description: viewModel.profileData!.username ?? '',
|
|
),
|
|
TitleDescription(
|
|
title: ProfileStrings.email,
|
|
description: viewModel.profileData!.email ?? '',
|
|
),
|
|
TitleDescription(
|
|
title: ProfileStrings.phone,
|
|
description: viewModel.profileData!.phone ?? '',
|
|
),
|
|
TitleDescription(
|
|
title: ProfileStrings.companyName,
|
|
description:
|
|
viewModel.profileData!.companies!.first.name ?? '',
|
|
),
|
|
SizedBox(height: 32.0.h()),
|
|
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()),
|
|
const Spacer(),
|
|
InkWell(
|
|
onTap: () => viewModel.logout(),
|
|
borderRadius: BorderRadius.circular(100),
|
|
child: Container(
|
|
width: double.infinity,
|
|
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),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|