frontendPlayer/lib/presentation/widgets/teacher_panel_scaffold.dart
2026-04-10 09:55:19 +03:30

224 lines
6.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../core/constants/app_colors.dart';
import '../../core/constants/app_text_styles.dart';
import '../../data/services/api_service.dart';
import '../pages/login_page.dart';
import 'sidebar_menu_item.dart';
enum PanelMenu { none, dashboard, course, license, transaction, ticket }
class TeacherPanelScaffold extends StatefulWidget {
final Widget child;
final PanelMenu selectedMenu;
final VoidCallback? onDashboardTap;
final VoidCallback? onCourseTap;
final VoidCallback? onLicenseTap;
final VoidCallback? onTransactionTap;
final VoidCallback? onTicketTap;
const TeacherPanelScaffold({
super.key,
required this.child,
this.selectedMenu = PanelMenu.none,
this.onDashboardTap,
this.onCourseTap,
this.onLicenseTap,
this.onTransactionTap,
this.onTicketTap,
});
@override
State<TeacherPanelScaffold> createState() => _TeacherPanelScaffoldState();
}
class _TeacherPanelScaffoldState extends State<TeacherPanelScaffold> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
void _goToLogin() {
Provider.of<ApiService>(context, listen: false).clearSession();
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => const LoginPage()),
);
}
void _handleDashboardTap() {
final isDesktop = MediaQuery.of(context).size.width > 900;
if (!isDesktop && Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
widget.onDashboardTap?.call();
}
void _handleCourseTap() {
final isDesktop = MediaQuery.of(context).size.width > 900;
if (!isDesktop && Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
widget.onCourseTap?.call();
}
void _handleLicenseTap() {
final isDesktop = MediaQuery.of(context).size.width > 900;
if (!isDesktop && Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
widget.onLicenseTap?.call();
}
void _handleTransactionTap() {
final isDesktop = MediaQuery.of(context).size.width > 900;
if (!isDesktop && Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
widget.onTransactionTap?.call();
}
void _handleTicketTap() {
final isDesktop = MediaQuery.of(context).size.width > 900;
if (!isDesktop && Navigator.of(context).canPop()) {
Navigator.of(context).pop();
}
widget.onTicketTap?.call();
}
Widget _buildSidebarContent() {
return Container(
color: AppColors.sidebarBg,
child: Column(
children: [
const SizedBox(height: 40),
Text(
'پنل مدرسین',
style: AppTextStyles.headlineMedium.copyWith(color: Colors.white),
),
const SizedBox(height: 40),
SidebarMenuItem(
title: 'داشبورد',
icon: Icons.dashboard,
isSelected: widget.selectedMenu == PanelMenu.dashboard,
onTap: _handleDashboardTap,
),
SidebarMenuItem(
title: 'دوره',
icon: Icons.school,
isSelected: widget.selectedMenu == PanelMenu.course,
onTap: _handleCourseTap,
),
SidebarMenuItem(
title: 'لایسنس',
icon: Icons.description,
isSelected: widget.selectedMenu == PanelMenu.license,
onTap: _handleLicenseTap,
),
SidebarMenuItem(
title: 'تراکنش',
icon: Icons.payment,
isSelected: widget.selectedMenu == PanelMenu.transaction,
onTap: _handleTransactionTap,
),
SidebarMenuItem(title: 'همکار', icon: Icons.people, onTap: () {}),
SidebarMenuItem(
title: 'تیکت',
icon: Icons.message,
isSelected: widget.selectedMenu == PanelMenu.ticket,
onTap: _handleTicketTap,
),
SidebarMenuItem(title: 'قوانین', icon: Icons.gavel, onTap: () {}),
const Spacer(),
ListTile(
leading: const Icon(Icons.logout, color: Colors.white),
title: const Text('خروج', style: TextStyle(color: Colors.white)),
onTap: _goToLogin,
),
const SizedBox(height: 20),
],
),
);
}
Widget _buildHeader(bool isDesktop) {
final apiService = context.watch<ApiService>();
final userName = apiService.currentUserName ?? 'کاربر';
final userPhone = apiService.currentUserPhone ?? '-';
return Container(
height: 80,
padding: const EdgeInsets.symmetric(horizontal: 24),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
const CircleAvatar(
backgroundImage: NetworkImage('https://i.pravatar.cc/150?img=11'),
),
const SizedBox(width: 12),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(userName, style: AppTextStyles.bodyLarge),
Text(userPhone, style: AppTextStyles.bodyMedium),
],
),
],
),
if (isDesktop)
ElevatedButton.icon(
onPressed: _goToLogin,
icon: const Icon(Icons.logout, size: 16),
label: const Text('خروج'),
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.sidebarBg,
foregroundColor: Colors.white,
),
)
else
IconButton(
icon: const Icon(Icons.menu),
onPressed: () => _scaffoldKey.currentState?.openEndDrawer(),
),
],
),
);
}
@override
Widget build(BuildContext context) {
final isDesktop = MediaQuery.of(context).size.width > 900;
return Scaffold(
key: _scaffoldKey,
backgroundColor: AppColors.background,
endDrawer: isDesktop ? null : Drawer(child: _buildSidebarContent()),
body: Directionality(
textDirection: TextDirection.rtl,
child: Row(
children: [
if (isDesktop) SizedBox(width: 250, child: _buildSidebarContent()),
Expanded(
child: Column(
children: [
_buildHeader(isDesktop),
Expanded(child: widget.child),
],
),
),
],
),
),
);
}
}