Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

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