選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

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