forked from hesabix/arc
522 lines
19 KiB
Dart
Executable file
522 lines
19 KiB
Dart
Executable file
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:hesabix_ui/l10n/app_localizations.dart';
|
|
import '../core/auth_store.dart';
|
|
import '../core/locale_controller.dart';
|
|
import '../core/calendar_controller.dart';
|
|
import '../theme/theme_controller.dart';
|
|
import 'calendar_switcher.dart';
|
|
import 'language_switcher.dart';
|
|
import 'theme_mode_switcher.dart';
|
|
import 'theme_palette_switcher.dart';
|
|
import '../utils/snackbar_helper.dart';
|
|
|
|
|
|
class CombinedUserMenuButton extends StatelessWidget {
|
|
final AuthStore authStore;
|
|
final LocaleController? localeController;
|
|
final CalendarController? calendarController;
|
|
final ThemeController? themeController;
|
|
/// نوار ابزار فشرده (مثلاً پنل کسبوکار): آواتار کوچکتر.
|
|
final bool denseToolbar;
|
|
|
|
const CombinedUserMenuButton({
|
|
super.key,
|
|
required this.authStore,
|
|
this.localeController,
|
|
this.calendarController,
|
|
this.themeController,
|
|
this.denseToolbar = false,
|
|
});
|
|
|
|
void _showUserMenu(BuildContext context) {
|
|
final t = AppLocalizations.of(context);
|
|
final cs = Theme.of(context).colorScheme;
|
|
final userName = authStore.currentUserName;
|
|
final userMobile = authStore.currentUserMobile;
|
|
final maskedMobile = _maskMobile(userMobile);
|
|
|
|
showDialog(
|
|
context: context,
|
|
barrierDismissible: true,
|
|
builder: (context) => Dialog(
|
|
backgroundColor: Colors.transparent,
|
|
elevation: 0,
|
|
child: Container(
|
|
constraints: const BoxConstraints(maxWidth: 320),
|
|
decoration: BoxDecoration(
|
|
color: cs.surface,
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withValues(alpha: 0.1),
|
|
blurRadius: 20,
|
|
offset: const Offset(0, 8),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
// Header ساده با آواتار و نام کاربر
|
|
Container(
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: cs.primaryContainer.withValues(alpha: 0.1),
|
|
borderRadius: const BorderRadius.only(
|
|
topLeft: Radius.circular(16),
|
|
topRight: Radius.circular(16),
|
|
),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
CircleAvatar(
|
|
radius: 24,
|
|
backgroundColor: cs.primary,
|
|
child: Icon(
|
|
Icons.person,
|
|
color: cs.onPrimary,
|
|
size: 28,
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
userName?.isNotEmpty == true ? userName! : t.profile,
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.w600,
|
|
color: cs.onSurface,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
// محتوای دیالوگ
|
|
Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
children: [
|
|
// نمایش شماره موبایل (فقط در صورت موجود بودن)
|
|
if (maskedMobile != null && maskedMobile.isNotEmpty) ...[
|
|
Row(
|
|
children: [
|
|
Icon(
|
|
Icons.phone_iphone,
|
|
color: cs.onSurfaceVariant,
|
|
size: 18,
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
maskedMobile,
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
color: cs.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
],
|
|
|
|
// آیتم حساب کاربری
|
|
Container(
|
|
width: double.infinity,
|
|
decoration: BoxDecoration(
|
|
color: cs.primaryContainer.withValues(alpha: 0.1),
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(
|
|
color: cs.primary.withValues(alpha: 0.2),
|
|
width: 1,
|
|
),
|
|
),
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
borderRadius: BorderRadius.circular(12),
|
|
onTap: () {
|
|
context.pop();
|
|
context.go('/user/profile/dashboard');
|
|
},
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Row(
|
|
children: [
|
|
CircleAvatar(
|
|
radius: 20,
|
|
backgroundColor: cs.primary,
|
|
child: Icon(
|
|
Icons.account_circle,
|
|
color: cs.onPrimary,
|
|
size: 24,
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
t.profile,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: cs.onSurface,
|
|
),
|
|
),
|
|
Text(
|
|
t.accountManagement,
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
color: cs.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Icon(
|
|
Icons.arrow_forward_ios,
|
|
color: cs.onSurfaceVariant,
|
|
size: 16,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
// بخش تنظیمات
|
|
Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest.withValues(alpha: 0.3),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(
|
|
Icons.settings,
|
|
color: cs.primary,
|
|
size: 20,
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
t.settings,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: cs.onSurface,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
// تنظیمات تقویم
|
|
if (calendarController != null) ...[
|
|
_buildSettingRow(
|
|
context,
|
|
icon: Icons.calendar_today,
|
|
title: t.calendar,
|
|
child: CalendarSwitcher(controller: calendarController!),
|
|
),
|
|
const SizedBox(height: 12),
|
|
],
|
|
|
|
// تنظیمات زبان
|
|
if (localeController != null) ...[
|
|
_buildSettingRow(
|
|
context,
|
|
icon: Icons.language,
|
|
title: t.language,
|
|
child: LanguageSwitcher(controller: localeController!),
|
|
),
|
|
const SizedBox(height: 12),
|
|
],
|
|
|
|
// تنظیمات تم
|
|
if (themeController != null) ...[
|
|
_buildSettingRow(
|
|
context,
|
|
icon: Icons.color_lens_outlined,
|
|
title: t.colorTheme,
|
|
child: ThemePaletteSwitcher(controller: themeController!),
|
|
),
|
|
const SizedBox(height: 8),
|
|
_buildSettingRow(
|
|
context,
|
|
icon: Icons.palette,
|
|
title: t.theme,
|
|
child: ThemeModeSwitcher(controller: themeController!),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
// دکمه خروج
|
|
Container(
|
|
width: double.infinity,
|
|
decoration: BoxDecoration(
|
|
color: cs.errorContainer.withValues(alpha: 0.1),
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(
|
|
color: cs.error.withValues(alpha: 0.2),
|
|
width: 1,
|
|
),
|
|
),
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
borderRadius: BorderRadius.circular(12),
|
|
onTap: () {
|
|
context.pop();
|
|
_confirmLogout(context);
|
|
},
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 12,
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.logout,
|
|
color: cs.error,
|
|
size: 20,
|
|
),
|
|
const SizedBox(width: 12),
|
|
Text(
|
|
t.logout,
|
|
style: TextStyle(
|
|
color: cs.error,
|
|
fontWeight: FontWeight.w500,
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildSettingRow(
|
|
BuildContext context, {
|
|
required IconData icon,
|
|
required String title,
|
|
required Widget child,
|
|
}) {
|
|
final cs = Theme.of(context).colorScheme;
|
|
|
|
return Row(
|
|
children: [
|
|
Icon(
|
|
icon,
|
|
color: cs.onSurfaceVariant,
|
|
size: 20,
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Text(
|
|
title,
|
|
style: TextStyle(
|
|
color: cs.onSurface,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
child,
|
|
],
|
|
);
|
|
}
|
|
|
|
/// ماسککردن شماره موبایل: نگهداشتن ۳ رقم اول و ۳ رقم آخر و ستارهکردن وسط
|
|
String? _maskMobile(String? mobile) {
|
|
if (mobile == null) return null;
|
|
final raw = mobile.replaceAll(RegExp(r'\\s+'), '');
|
|
if (raw.length <= 6) {
|
|
return raw;
|
|
}
|
|
final start = raw.substring(0, 3);
|
|
final end = raw.substring(raw.length - 3);
|
|
final maskedCount = raw.length - 6;
|
|
final stars = '*' * maskedCount;
|
|
return '$start$stars$end';
|
|
}
|
|
|
|
void _confirmLogout(BuildContext context) {
|
|
final t = AppLocalizations.of(context);
|
|
final cs = Theme.of(context).colorScheme;
|
|
|
|
showDialog(
|
|
context: context,
|
|
barrierDismissible: true,
|
|
builder: (context) => Dialog(
|
|
backgroundColor: Colors.transparent,
|
|
elevation: 0,
|
|
child: Container(
|
|
constraints: const BoxConstraints(maxWidth: 400),
|
|
decoration: BoxDecoration(
|
|
color: cs.surface,
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withValues(alpha: 0.1),
|
|
blurRadius: 20,
|
|
offset: const Offset(0, 8),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
// Header
|
|
Container(
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: cs.errorContainer.withValues(alpha: 0.1),
|
|
borderRadius: const BorderRadius.only(
|
|
topLeft: Radius.circular(16),
|
|
topRight: Radius.circular(16),
|
|
),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
CircleAvatar(
|
|
radius: 20,
|
|
backgroundColor: cs.error,
|
|
child: Icon(
|
|
Icons.logout,
|
|
color: cs.onError,
|
|
size: 20,
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Text(
|
|
t.logoutConfirmTitle,
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.w600,
|
|
color: cs.onSurface,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
// Content
|
|
Padding(
|
|
padding: const EdgeInsets.all(20),
|
|
child: Text(
|
|
t.logoutConfirmMessage,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
color: cs.onSurfaceVariant,
|
|
height: 1.5,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
|
|
// Actions
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: OutlinedButton(
|
|
onPressed: () => context.pop(),
|
|
style: OutlinedButton.styleFrom(
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
),
|
|
child: Text(t.cancel),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: FilledButton(
|
|
onPressed: () async {
|
|
context.pop();
|
|
await authStore.saveApiKey(null);
|
|
if (!context.mounted) return;
|
|
SnackBarHelper.show(context, message: t.logoutDone);
|
|
context.go('/login');
|
|
},
|
|
style: FilledButton.styleFrom(
|
|
backgroundColor: cs.error,
|
|
foregroundColor: cs.onError,
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
),
|
|
child: Text(t.logout),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cs = Theme.of(context).colorScheme;
|
|
|
|
final double avatarR = denseToolbar ? 12 : 16;
|
|
final double iconSz = denseToolbar ? 14 : 18;
|
|
return IconButton(
|
|
visualDensity: denseToolbar ? VisualDensity.compact : VisualDensity.standard,
|
|
style: denseToolbar
|
|
? IconButton.styleFrom(
|
|
minimumSize: const Size(34, 34),
|
|
padding: const EdgeInsets.all(4),
|
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
)
|
|
: null,
|
|
icon: CircleAvatar(
|
|
radius: avatarR,
|
|
backgroundColor: cs.surfaceContainerHighest,
|
|
foregroundColor: cs.onSurface,
|
|
child: Icon(Icons.person, size: iconSz),
|
|
),
|
|
onPressed: () => _showUserMenu(context),
|
|
tooltip: AppLocalizations.of(context).profile,
|
|
);
|
|
}
|
|
}
|