25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

317 lines
11 KiB

  1. // ignore_for_file: public_member_api_docs, sort_constructors_first
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_gen/gen_l10n/app_localizations.dart';
  4. import 'package:font_awesome_flutter/font_awesome_flutter.dart';
  5. import 'package:go_router/go_router.dart';
  6. import 'package:provider/provider.dart';
  7. import 'package:qadirneyriz/config/config.dart';
  8. import 'package:qadirneyriz/screens/aboutUs/screen.dart';
  9. import 'package:qadirneyriz/screens/auth/state/state.dart';
  10. import 'package:qadirneyriz/screens/change_pass/screen.dart';
  11. import 'package:qadirneyriz/screens/home/screen.dart';
  12. import 'package:qadirneyriz/screens/home/state.dart';
  13. import 'package:qadirneyriz/screens/meeting/screen.dart';
  14. import 'package:qadirneyriz/screens/private_meeting/screen.dart';
  15. import 'package:qadirneyriz/screens/report/screen.dart';
  16. import 'package:qadirneyriz/setting/setting.dart';
  17. class CustomDrawerNavigation extends StatefulWidget {
  18. final int activeTab;
  19. const CustomDrawerNavigation({super.key, required this.activeTab});
  20. @override
  21. _CustomDrawerNavigationState createState() => _CustomDrawerNavigationState();
  22. }
  23. class _CustomDrawerNavigationState extends State<CustomDrawerNavigation> {
  24. late final PageController _pageController;
  25. int _selectedIndex = 0;
  26. final String language = setting.userLocalDb.getUser().language;
  27. String? selectedLanguage; // زبان پیش‌فرض فارسی
  28. late AuthState state;
  29. @override
  30. void initState() {
  31. super.initState();
  32. state = Provider.of(context, listen: false);
  33. selectedLanguage = language;
  34. _selectedIndex = widget.activeTab;
  35. _pageController = PageController(initialPage: _selectedIndex);
  36. }
  37. final List<Widget> _bottomBarPages = [
  38. const HomeScreen(),
  39. const MeetingsScreen(),
  40. const PrivateMeetingsScreen(),
  41. const ReportScreen(),
  42. const ChangePassScreen(),
  43. const AboutUsScreen()
  44. // Add more screens here
  45. ];
  46. void _onItemTapped(int index) {
  47. setState(() {
  48. _selectedIndex = index;
  49. });
  50. _pageController.jumpToPage(index);
  51. Navigator.pop(context); // Close the drawer
  52. }
  53. @override
  54. Widget build(BuildContext context) {
  55. final userRole = setting.userLocalDb.getUser().role;
  56. return Scaffold(
  57. // backgroundColor: Colors.green.withOpacity(.2),
  58. drawer: Consumer<AuthState>(
  59. builder: (context, value, child) {
  60. return Drawer(
  61. backgroundColor: config.ui.backGroundColor,
  62. child: SingleChildScrollView(
  63. child: Column(
  64. crossAxisAlignment: CrossAxisAlignment.start,
  65. children: <Widget>[
  66. Padding(
  67. padding: const EdgeInsets.symmetric(
  68. horizontal: 10, vertical: 35),
  69. child: Image.asset(
  70. 'assets/images/D2.png', // مسیر لوگوی شما
  71. height: 60,
  72. ),
  73. ),
  74. if (userRole == 0 || userRole == 2)
  75. Padding(
  76. padding: const EdgeInsets.symmetric(horizontal: 5),
  77. child: Row(
  78. children: [
  79. Expanded(
  80. child: Consumer<HomeState>(
  81. builder: (context, value, child) {
  82. return NewSessionButton(
  83. title:
  84. AppLocalizations.of(context)!.newmeeting,
  85. icon: Icons.person_outlined,
  86. onPressed: () async {
  87. await context.pushNamed('meetingadd');
  88. value.getTodayMeetings();
  89. },
  90. );
  91. },
  92. ),
  93. ),
  94. Expanded(
  95. child: NewSessionButton(
  96. title: AppLocalizations.of(context)!
  97. .newprivatemeeting,
  98. icon: Icons.people_outlined,
  99. onPressed: () {
  100. context.pushNamed('privatemeetingadd');
  101. },
  102. ),
  103. ),
  104. ],
  105. ),
  106. ),
  107. Padding(
  108. padding: const EdgeInsets.symmetric(vertical: 50),
  109. child: ListView(
  110. shrinkWrap: true,
  111. physics: const NeverScrollableScrollPhysics(),
  112. padding: EdgeInsets.zero,
  113. children: <Widget>[
  114. _buildDrawerItem(
  115. icon: FontAwesomeIcons.house,
  116. text: AppLocalizations.of(context)!.home,
  117. index: 0,
  118. ),
  119. _buildDrawerItem(
  120. icon: FontAwesomeIcons.peopleGroup,
  121. text: AppLocalizations.of(context)!.meetings,
  122. index: 1,
  123. ),
  124. _buildDrawerItem(
  125. icon: FontAwesomeIcons.calendar,
  126. text: AppLocalizations.of(context)!.privatemeeting,
  127. index: 2,
  128. ),
  129. _buildDrawerItem(
  130. icon: FontAwesomeIcons.chartColumn,
  131. text: AppLocalizations.of(context)!.reports,
  132. index: 3,
  133. ),
  134. _buildDrawerItem(
  135. icon: FontAwesomeIcons.person,
  136. text: AppLocalizations.of(context)!.profile,
  137. index: 4,
  138. ),
  139. _buildDrawerItem(
  140. icon: FontAwesomeIcons.info,
  141. text: AppLocalizations.of(context)!.aboutus,
  142. index: 5,
  143. ),
  144. ],
  145. ),
  146. ),
  147. Padding(
  148. padding: const EdgeInsets.all(8.0),
  149. child: Container(
  150. decoration: BoxDecoration(
  151. color: config.ui.secendGreen.withOpacity(.1),
  152. borderRadius: BorderRadius.circular(10),
  153. ),
  154. child: Padding(
  155. padding: const EdgeInsets.all(8.0),
  156. child: Row(
  157. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  158. children: [
  159. _buildLanguageButton('fa', 'فارسی', () {
  160. value.setLocale('fa');
  161. }),
  162. _buildLanguageButton('en', 'English', () {
  163. value.setLocale('en');
  164. }),
  165. ],
  166. ),
  167. ),
  168. ),
  169. ),
  170. ],
  171. ),
  172. ),
  173. );
  174. },
  175. ),
  176. body: Container(
  177. decoration: BoxDecoration(
  178. color: config.ui.backGroundColor,
  179. ),
  180. child: PageView(
  181. controller: _pageController,
  182. physics: const NeverScrollableScrollPhysics(),
  183. children: _bottomBarPages,
  184. ),
  185. ),
  186. );
  187. }
  188. Widget _buildDrawerItem(
  189. {required IconData icon, required String text, required int index}) {
  190. bool isSelected = _selectedIndex == index;
  191. return Padding(
  192. padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 2),
  193. child: Material(
  194. color: isSelected
  195. ? config.ui.secendGreen.withOpacity(.1)
  196. : Colors.transparent,
  197. borderRadius: BorderRadius.circular(8),
  198. child: InkWell(
  199. borderRadius: BorderRadius.circular(8),
  200. onTap: () => _onItemTapped(index),
  201. child: Container(
  202. decoration: BoxDecoration(
  203. borderRadius: BorderRadius.circular(8),
  204. ),
  205. child: ListTile(
  206. leading: FaIcon(
  207. icon,
  208. size: 19,
  209. color: isSelected ? config.ui.secendGreen : config.ui.mainGray,
  210. ),
  211. title: Text(
  212. text,
  213. style: TextStyle(
  214. color:
  215. isSelected ? config.ui.secendGreen : config.ui.mainGray,
  216. fontWeight:
  217. isSelected ? FontWeight.bold : FontWeight.normal,
  218. fontSize: 15),
  219. ),
  220. selected: isSelected,
  221. ),
  222. ),
  223. ),
  224. ),
  225. );
  226. }
  227. Widget _buildLanguageButton(
  228. String language, String text, void Function() onPressed) {
  229. bool isSelected = selectedLanguage == language;
  230. return ElevatedButton(
  231. onPressed: () {
  232. setState(() {
  233. selectedLanguage = language; // به‌روز کردن زبان انتخاب شده
  234. });
  235. onPressed(); // اجرای متد تغییر زبان
  236. },
  237. style: ElevatedButton.styleFrom(
  238. backgroundColor: isSelected ? Colors.green : Colors.white,
  239. shape: RoundedRectangleBorder(
  240. borderRadius: BorderRadius.circular(5.0),
  241. ),
  242. ),
  243. child: Text(
  244. text,
  245. style: TextStyle(
  246. color: isSelected ? Colors.white : Colors.black, fontSize: 13),
  247. ),
  248. );
  249. }
  250. @override
  251. void dispose() {
  252. _pageController.dispose();
  253. super.dispose();
  254. }
  255. }
  256. class NewSessionButton extends StatelessWidget {
  257. final void Function()? onPressed;
  258. final String title;
  259. final IconData icon;
  260. const NewSessionButton({
  261. Key? key,
  262. this.onPressed,
  263. required this.title,
  264. required this.icon,
  265. }) : super(key: key);
  266. @override
  267. Widget build(BuildContext context) {
  268. return Padding(
  269. padding: const EdgeInsets.symmetric(horizontal: 5),
  270. child: ElevatedButton(
  271. style: ElevatedButton.styleFrom(
  272. backgroundColor: config.ui.mainGreen, // رنگ لبه‌ها
  273. shape: RoundedRectangleBorder(
  274. borderRadius: BorderRadius.circular(8), // گرد کردن گوشه‌ها
  275. ),
  276. elevation: 0, // بدون سایه
  277. padding: EdgeInsets.symmetric(vertical: 20, horizontal: 16),
  278. ),
  279. onPressed: onPressed,
  280. child: Column(
  281. mainAxisSize: MainAxisSize.min,
  282. children: [
  283. Icon(
  284. icon,
  285. color: Colors.white, // رنگ آیکون
  286. size: 40,
  287. ),
  288. SizedBox(height: 8),
  289. Text(
  290. title,
  291. style: TextStyle(
  292. color: Colors.white, // رنگ متن
  293. fontSize: 11,
  294. fontWeight: FontWeight.normal,
  295. ),
  296. ),
  297. ],
  298. ),
  299. ),
  300. );
  301. }
  302. }