dashboard_view.dart 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. // ignore_for_file: unused_local_variable, unused_field, non_constant_identifier_names, depend_on_referenced_packages
  2. import 'package:flutter/material.dart';
  3. import 'package:gozap_package/components/coloredcontainer.dart';
  4. import 'package:gozap_package/components/icons/gozap_icons.dart';
  5. import 'package:gozap_package/components/quantity_input.dart';
  6. import 'package:gozap_package/components/responsive.dart';
  7. import 'package:gozap_package/components/themes/themes.dart';
  8. import 'package:gozap_package/models/user/user_model.dart';
  9. import 'package:gozap_package/views/log_in/log_in_view.dart';
  10. import 'package:intl/intl.dart';
  11. import 'package:provider/provider.dart';
  12. import 'package:qr_flutter/qr_flutter.dart';
  13. // import model
  14. import '/models/dashboard/dashboard_model.dart';
  15. // import controller
  16. import '/controllers/dashboard/dashboard_controller.dart';
  17. enum Menu { itemOne, itemTwo, itemThree, itemFour }
  18. class DashboardView extends StatefulWidget {
  19. const DashboardView({super.key});
  20. @override
  21. State<DashboardView> createState() => _DashboardViewState();
  22. }
  23. class _DashboardViewState extends State<DashboardView> {
  24. int simpleIntInput = 1;
  25. final String _selectedMenu = '';
  26. @override
  27. Widget build(BuildContext context) {
  28. DashboardController viewController = DashboardController();
  29. return ChangeNotifierProvider<DashboardModel>(
  30. create: (context) => DashboardModel.instance(context),
  31. child: Consumer<DashboardModel>(
  32. builder: (context, viewModel, child) {
  33. if (viewModel.status == DashboardModelStatus.Loading) {
  34. return const Center(
  35. child: CircularProgressIndicator.adaptive(),
  36. );
  37. } else if (viewModel.swapModule == null) {
  38. return const Center(
  39. child: Text("Somthing went wrong"),
  40. );
  41. } else {
  42. var topBarWidget = Row(
  43. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  44. children: [
  45. SizedBox(
  46. child: Card(
  47. elevation: 10,
  48. shape: RoundedRectangleBorder(
  49. borderRadius: BorderRadius.circular(15),
  50. ),
  51. child: ClipRRect(
  52. borderRadius: const BorderRadius.all(Radius.circular(15)),
  53. child: Image.asset(
  54. 'assets/images/logos/gozap_small_color_logo.png',
  55. width: 50,
  56. fit: BoxFit.cover,
  57. package: "gozap_package",
  58. ),
  59. ),
  60. ),
  61. ),
  62. SizedBox(
  63. width: 50,
  64. child: Card(
  65. elevation: 10,
  66. shape: RoundedRectangleBorder(
  67. borderRadius: BorderRadius.circular(15),
  68. ),
  69. child: ClipRRect(
  70. borderRadius: const BorderRadius.all(Radius.circular(15)),
  71. child: PopupMenuButton(
  72. onSelected: ((Menu item) {
  73. if (item == Menu.itemFour) {
  74. Provider.of<userChangeNotifier>(context,
  75. listen: false)
  76. .remove(
  77. context,
  78. LogInView(
  79. nextScreen: const DashboardView()));
  80. }
  81. }),
  82. position: PopupMenuPosition.under,
  83. padding: const EdgeInsets.all(0),
  84. icon: Image.asset(
  85. 'assets/images/personal_info_profile.png',
  86. width: 100,
  87. fit: BoxFit.cover,
  88. package: "gozap_package",
  89. ),
  90. itemBuilder: (BuildContext context) =>
  91. <PopupMenuEntry<Menu>>[
  92. const PopupMenuItem<Menu>(
  93. value: Menu.itemOne,
  94. child: Text('Profile'),
  95. ),
  96. const PopupMenuItem<Menu>(
  97. value: Menu.itemTwo,
  98. child: Text('Swap Report'),
  99. ),
  100. const PopupMenuItem<Menu>(
  101. value: Menu.itemThree,
  102. child: Text('Recharge Report'),
  103. ),
  104. const PopupMenuItem<Menu>(
  105. value: Menu.itemFour,
  106. child: Text('Logout'),
  107. ),
  108. ]),
  109. ),
  110. ),
  111. ),
  112. ],
  113. );
  114. var riderIDTextWidget = SelectableText(
  115. "Rider ID - ${viewModel.swapModule!.User.PhoneNumber}",
  116. style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
  117. );
  118. var qrCodeWidget = Card(
  119. elevation: 10,
  120. child: ColoredContainer(
  121. containerColor: AppTheme.whiteColor.withOpacity(0.5),
  122. child: QrImage(
  123. data: viewModel.swapModule!.User.PhoneNumber,
  124. version: QrVersions.auto,
  125. size: 200.0,
  126. ),
  127. ),
  128. );
  129. var countCardsWidget = Wrap(
  130. alignment: WrapAlignment.center,
  131. runAlignment: WrapAlignment.center,
  132. crossAxisAlignment: WrapCrossAlignment.center,
  133. runSpacing: 20,
  134. spacing: 20,
  135. children: [
  136. ColoredContainer(
  137. child: Row(
  138. children: [
  139. const Padding(
  140. padding: EdgeInsets.all(5),
  141. child: Icon(
  142. GoZAPPIcon.remaing_swaps,
  143. ),
  144. ),
  145. Expanded(
  146. child: Column(
  147. children: [
  148. const Text("Remaing Swaps"),
  149. Text(
  150. "${viewModel.swapModule!.RemaingSwap.Available}/${viewModel.swapModule!.RemaingSwap.Total}",
  151. style: const TextStyle(
  152. fontSize: 18, fontWeight: FontWeight.w700),
  153. ),
  154. ],
  155. ),
  156. ),
  157. ],
  158. )),
  159. ColoredContainer(
  160. containerColor: AppTheme.organeColor.withOpacity(0.2),
  161. child: Row(
  162. children: [
  163. const Padding(
  164. padding: EdgeInsets.all(5),
  165. child: Icon(GoZAPPIcon.free_swaps),
  166. ),
  167. Expanded(
  168. child: Column(
  169. children: [
  170. const Text("No. free Swaps"),
  171. Text(
  172. "${viewModel.swapModule!.FreeSwap.Available}/${viewModel.swapModule!.FreeSwap.Total}",
  173. style: const TextStyle(
  174. fontSize: 18, fontWeight: FontWeight.w700),
  175. ),
  176. ],
  177. ),
  178. ),
  179. ],
  180. )),
  181. ColoredContainer(
  182. containerColor: AppTheme.pinkColor.withOpacity(0.2),
  183. child: Row(
  184. children: [
  185. const Padding(
  186. padding: EdgeInsets.all(5),
  187. child: Icon(GoZAPPIcon.month_swaps),
  188. ),
  189. Expanded(
  190. child: Column(
  191. children: [
  192. const Text("No. Month Swaps"),
  193. Text(
  194. "${viewModel.swapModule!.SwapHistoryMeta.TotalCount}",
  195. style: const TextStyle(
  196. fontSize: 18, fontWeight: FontWeight.w700),
  197. ),
  198. ],
  199. ),
  200. ),
  201. ],
  202. )),
  203. ColoredContainer(
  204. containerColor: AppTheme.blueColor.withOpacity(0.2),
  205. child: Row(
  206. children: [
  207. const Padding(
  208. padding: EdgeInsets.all(5),
  209. child: Icon(GoZAPPIcon.recharged_swaps),
  210. ),
  211. Expanded(
  212. child: Column(
  213. children: [
  214. const Text("Recharged Swaps"),
  215. Text(
  216. "${viewModel.swapModule!.RechargeSwap.Available}/${viewModel.swapModule!.RechargeSwap.Total}",
  217. style: const TextStyle(
  218. fontSize: 18, fontWeight: FontWeight.w700),
  219. ),
  220. ],
  221. ),
  222. ),
  223. ],
  224. )),
  225. ],
  226. );
  227. var swapRechargeCountWidget = Row(
  228. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  229. children: [
  230. const Text(
  231. "Swaps",
  232. style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700),
  233. ),
  234. QuantityInput(
  235. readOnly: true,
  236. value: simpleIntInput,
  237. onChanged: (value) => setState(() => simpleIntInput =
  238. int.parse(
  239. value.replaceAll(',', '').replaceAll('.', '')))),
  240. ],
  241. );
  242. var swapReferTextWidget = const Padding(
  243. padding: EdgeInsets.all(8.0),
  244. child: Text("Refer 1 member & get 3 Swaps free"),
  245. );
  246. var swapReferAndPayButtonWidget = Row(
  247. children: [
  248. Expanded(
  249. child: OutlinedButton(
  250. onPressed: () {},
  251. child: const Text(
  252. "Refer",
  253. style: TextStyle(
  254. fontSize: 16, fontWeight: FontWeight.w500),
  255. )),
  256. ),
  257. const SizedBox(
  258. width: 10,
  259. ),
  260. Expanded(
  261. child: ElevatedButton(
  262. onPressed: () {},
  263. child: const Text(
  264. "Pay",
  265. style: TextStyle(
  266. fontSize: 16, fontWeight: FontWeight.w500),
  267. )),
  268. ),
  269. ],
  270. );
  271. return Scaffold(
  272. body: SafeArea(
  273. child: SizedBox(
  274. width: double.infinity,
  275. child: SingleChildScrollView(
  276. scrollDirection: Axis.vertical,
  277. child: Padding(
  278. padding: const EdgeInsets.all(15),
  279. child: ResponsiveWidget(
  280. mobileBody: Column(
  281. children: [
  282. topBarWidget,
  283. const SizedBox(
  284. height: 20,
  285. ),
  286. riderIDTextWidget,
  287. qrCodeWidget,
  288. const SizedBox(
  289. height: 20,
  290. ),
  291. countCardsWidget,
  292. const SizedBox(
  293. height: 20,
  294. ),
  295. swapRechargeCountWidget,
  296. swapReferTextWidget,
  297. swapReferAndPayButtonWidget
  298. ],
  299. ),
  300. desktopBody: Column(children: [
  301. topBarWidget,
  302. Row(
  303. crossAxisAlignment: CrossAxisAlignment.start,
  304. children: [
  305. Expanded(
  306. child: Column(
  307. crossAxisAlignment: CrossAxisAlignment.start,
  308. children: [
  309. Padding(
  310. padding: const EdgeInsets.all(10),
  311. child: Text(
  312. "Dashbaord",
  313. style: TextStyle(
  314. fontSize: 24,
  315. color: AppTheme.primaryColor),
  316. ),
  317. ),
  318. countCardsWidget,
  319. ],
  320. )),
  321. Expanded(
  322. child: Column(
  323. crossAxisAlignment: CrossAxisAlignment.start,
  324. children: [
  325. Padding(
  326. padding: const EdgeInsets.all(20),
  327. child: Text(
  328. "Report",
  329. style: TextStyle(
  330. fontSize: 24,
  331. color: AppTheme.primaryColor),
  332. ),
  333. ),
  334. Column(
  335. children: viewModel.swapModule!
  336. .SwapHistoryMeta.SwapHistoryList
  337. .map(
  338. (History) {
  339. var date = DateFormat('MMM dd, yyyy')
  340. .format(History.SwapCreatedAt);
  341. return ListTile(
  342. leading: CircleAvatar(
  343. radius: 5,
  344. backgroundColor:
  345. (History.IsFreeSwap)
  346. ? null
  347. : AppTheme.redColor,
  348. ),
  349. title: Text(History.SwapFormattedCreatedAt));
  350. },
  351. ).toList(),
  352. ),
  353. ],
  354. )),
  355. Expanded(
  356. child: Column(
  357. children: [
  358. Padding(
  359. padding: const EdgeInsets.all(10),
  360. child: SelectableText(
  361. "Rider ID - ${viewModel.swapModule!.User.PhoneNumber}",
  362. style: TextStyle(
  363. fontSize: 24,
  364. color: AppTheme.primaryColor),
  365. ),
  366. ),
  367. qrCodeWidget,
  368. const SizedBox(
  369. height: 20,
  370. ),
  371. // riderIDTextWidget,
  372. // const SizedBox(
  373. // height: 20,
  374. // ),
  375. swapRechargeCountWidget,
  376. swapReferTextWidget,
  377. swapReferAndPayButtonWidget
  378. ],
  379. )),
  380. ],
  381. )
  382. ]),
  383. ),
  384. ),
  385. ),
  386. )),
  387. );
  388. }
  389. },
  390. ),
  391. );
  392. }
  393. }