Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

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