buildUserProfile method
Implementation
Widget buildUserProfile(BuildContext context, {Color? textColor, Color? iconColor}) {
final userName = storageUtils.getUserName() ?? 'User';
final role = storageUtils.getAclPositionMappingName() ?? 'Role'; // <-- add this method
final roleName = AppUtils.extractLastRole(role);
return PopupMenuButton<String>(
offset: const Offset(0, 55),
elevation: 8,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(14),
),
onSelected: onSelected ??
(String value) {
switch (value) {
case 'birthday':
homeController.setEndDrawerContent(context, EventsDrawer());
break;
case 'change_password':
homeController.changePassword();
break;
case 'settings':
homeController.navigateToSettingScreen();
break;
case 'logout':
homeController.postLogOutAPI();
break;
}
},
itemBuilder: (BuildContext context) => [
/// 🔥 PROFILE HEADER
PopupMenuItem(
enabled: false,
padding: EdgeInsets.zero,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.grey.withOpacity(0.2)),
),
),
child: Row(
children: [
const ProfileAvatar(
imagePath: 'assets/images/demo_profile.png',
height: 45,
width: 45,
),
const SizedBox(width: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppText(
userName,
style: TextStyles.mediumBold(context),
),
const SizedBox(height: 4),
AppText(
roleName,
style: TextStyles.normal(context),
),
],
)
],
),
),
),
/// 🔹 SECTION: GENERAL
_buildMenuItem(
context,
value: 'birthday',
icon: CupertinoIcons.calendar,
title: AppStrings.birthday,
),
_buildMenuItem(
context,
value: 'change_password',
icon: CupertinoIcons.lock_open,
title: AppStrings.changePassword,
),
_buildMenuItem(
context,
value: 'settings',
icon: CupertinoIcons.gear,
title: AppStrings.settings,
),
/// 🔸 DIVIDER
const PopupMenuDivider(),
/// 🚪 LOGOUT (highlighted)
_buildMenuItem(
context,
value: 'logout',
icon: CupertinoIcons.square_arrow_right,
title: AppStrings.logout,
isDestructive: true,
),
],
/// 🔘 TRIGGER BUTTON
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
child: Row(
children: [
const ProfileAvatar(
imagePath: 'assets/images/demo_profile.png',
height: 35,
width: 35,
),
const SizedBox(width: 10),
AppText(userName, style: TextStyles.normal(context, textColor: textColor)),
const SizedBox(width: 5),
Icon(Icons.keyboard_arrow_down_rounded, color: iconColor),
],
),
),
);
}