You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

325 lines
11KB

  1. import 'package:farm_tpf/authentication/authentication.dart';
  2. import 'package:farm_tpf/presentation/screens/notification/sc_notification.dart';
  3. import 'package:farm_tpf/presentation/screens/profile/sc_update_profile.dart';
  4. import 'package:farm_tpf/utils/const_color.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_bloc/flutter_bloc.dart';
  7. class HomeDrawer extends StatefulWidget {
  8. const HomeDrawer(
  9. {Key key,
  10. this.screenIndex,
  11. this.iconAnimationController,
  12. this.callBackIndex})
  13. : super(key: key);
  14. final AnimationController iconAnimationController;
  15. final DrawerIndex screenIndex;
  16. final Function(DrawerIndex) callBackIndex;
  17. @override
  18. _HomeDrawerState createState() => _HomeDrawerState();
  19. }
  20. class _HomeDrawerState extends State<HomeDrawer> {
  21. List<DrawerList> drawerList;
  22. @override
  23. void initState() {
  24. setdDrawerListArray();
  25. super.initState();
  26. }
  27. void setdDrawerListArray() {
  28. drawerList = <DrawerList>[
  29. DrawerList(
  30. index: DrawerIndex.ScanBarcode,
  31. labelName: "Quét mã QR",
  32. icon: Icon(Icons.scanner)),
  33. DrawerList(
  34. index: DrawerIndex.Home,
  35. labelName: 'Danh sách lô',
  36. icon: Icon(Icons.home),
  37. ),
  38. DrawerList(
  39. index: DrawerIndex.ControlDevice,
  40. labelName: 'Điều khiển thiết bị',
  41. icon: Icon(Icons.device_hub),
  42. )
  43. ];
  44. }
  45. @override
  46. Widget build(BuildContext context) {
  47. return Container(
  48. child: Column(
  49. crossAxisAlignment: CrossAxisAlignment.stretch,
  50. mainAxisAlignment: MainAxisAlignment.start,
  51. children: <Widget>[
  52. Container(
  53. width: double.infinity,
  54. padding: const EdgeInsets.only(top: 45.0),
  55. child: Container(
  56. padding: const EdgeInsets.all(16.0),
  57. child: Column(
  58. crossAxisAlignment: CrossAxisAlignment.start,
  59. mainAxisAlignment: MainAxisAlignment.start,
  60. children: <Widget>[
  61. AnimatedBuilder(
  62. animation: widget.iconAnimationController,
  63. builder: (BuildContext context, Widget child) {
  64. return ScaleTransition(
  65. scale: AlwaysStoppedAnimation<double>(
  66. 1.0 - (widget.iconAnimationController.value) * 0.2),
  67. child: RotationTransition(
  68. turns: AlwaysStoppedAnimation<double>(Tween<double>(
  69. begin: 0.0, end: 24.0)
  70. .animate(CurvedAnimation(
  71. parent: widget.iconAnimationController,
  72. curve: Curves.fastOutSlowIn))
  73. .value /
  74. 360),
  75. child: Container(
  76. height: 100,
  77. width: 100,
  78. decoration: BoxDecoration(
  79. borderRadius: BorderRadius.circular(120),
  80. border: Border.all(
  81. width: 0.35, color: COLOR_CONST.DEFAULT),
  82. ),
  83. child: ClipRRect(
  84. borderRadius:
  85. const BorderRadius.all(Radius.circular(10.0)),
  86. child: FlutterLogo(
  87. size: 10,
  88. ),
  89. ),
  90. ),
  91. ),
  92. );
  93. },
  94. ),
  95. Padding(
  96. padding: const EdgeInsets.only(top: 8, left: 20),
  97. child: Text(
  98. 'Võ Phước Đại',
  99. style: TextStyle(
  100. fontWeight: FontWeight.w600,
  101. color: COLOR_CONST.GRAY1,
  102. fontSize: 18,
  103. ),
  104. ),
  105. ),
  106. ],
  107. ),
  108. ),
  109. ),
  110. const SizedBox(
  111. height: 4,
  112. ),
  113. Divider(
  114. height: 1,
  115. color: COLOR_CONST.GRAY1,
  116. ),
  117. Expanded(
  118. child: ListView.builder(
  119. physics: const BouncingScrollPhysics(),
  120. padding: const EdgeInsets.all(0.0),
  121. itemCount: drawerList.length,
  122. itemBuilder: (BuildContext context, int index) {
  123. return inkwell(drawerList[index]);
  124. },
  125. ),
  126. ),
  127. Divider(
  128. height: 1,
  129. color: COLOR_CONST.GRAY1,
  130. ),
  131. Column(
  132. children: <Widget>[
  133. ListTile(
  134. title: Text(
  135. 'Thông báo',
  136. style: TextStyle(
  137. fontWeight: FontWeight.w600,
  138. fontSize: 16,
  139. ),
  140. textAlign: TextAlign.left,
  141. ),
  142. leading: Icon(
  143. Icons.notifications,
  144. color: Colors.black,
  145. ),
  146. onTap: () {
  147. Navigator.of(context).push(
  148. MaterialPageRoute(builder: (_) => NotificationScreen()));
  149. },
  150. ),
  151. SizedBox(
  152. height: 2.0,
  153. ),
  154. ListTile(
  155. title: Text(
  156. 'Cài đặt',
  157. style: TextStyle(
  158. fontWeight: FontWeight.w600,
  159. fontSize: 16,
  160. ),
  161. textAlign: TextAlign.left,
  162. ),
  163. leading: Icon(
  164. Icons.settings,
  165. color: Colors.black,
  166. ),
  167. onTap: () {
  168. Navigator.of(context).push(
  169. MaterialPageRoute(builder: (_) => UpdateProfileScreen()));
  170. },
  171. ),
  172. SizedBox(
  173. height: 2.0,
  174. ),
  175. ListTile(
  176. title: Text(
  177. 'Đăng xuất',
  178. style: TextStyle(
  179. fontWeight: FontWeight.w600,
  180. fontSize: 16,
  181. ),
  182. textAlign: TextAlign.left,
  183. ),
  184. leading: Icon(
  185. Icons.power_settings_new,
  186. color: Colors.red,
  187. ),
  188. onTap: () {
  189. _clickSignOut();
  190. },
  191. ),
  192. SizedBox(
  193. height: MediaQuery.of(context).padding.bottom,
  194. )
  195. ],
  196. ),
  197. ],
  198. ),
  199. );
  200. }
  201. Widget inkwell(DrawerList listData) {
  202. return Material(
  203. color: Colors.white,
  204. child: InkWell(
  205. splashColor: Colors.grey.withOpacity(0.1),
  206. highlightColor: Colors.transparent,
  207. onTap: () {
  208. navigationtoScreen(listData.index);
  209. },
  210. child: Stack(
  211. children: <Widget>[
  212. Container(
  213. padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
  214. child: Row(
  215. children: <Widget>[
  216. Container(
  217. width: 6.0,
  218. height: 46.0,
  219. ),
  220. const Padding(
  221. padding: EdgeInsets.all(4.0),
  222. ),
  223. listData.isAssetsImage
  224. ? Container(
  225. width: 24,
  226. height: 24,
  227. child: Image.asset(listData.imageName,
  228. color: widget.screenIndex == listData.index
  229. ? COLOR_CONST.DEFAULT
  230. : COLOR_CONST.BLACK),
  231. )
  232. : Icon(listData.icon.icon,
  233. color: widget.screenIndex == listData.index
  234. ? COLOR_CONST.DEFAULT
  235. : COLOR_CONST.BLACK),
  236. const Padding(
  237. padding: EdgeInsets.all(4.0),
  238. ),
  239. Text(
  240. listData.labelName,
  241. style: TextStyle(
  242. fontWeight: FontWeight.w500,
  243. fontSize: 16,
  244. color: widget.screenIndex == listData.index
  245. ? COLOR_CONST.DEFAULT
  246. : COLOR_CONST.BLACK,
  247. ),
  248. textAlign: TextAlign.left,
  249. ),
  250. ],
  251. ),
  252. ),
  253. widget.screenIndex == listData.index
  254. ? AnimatedBuilder(
  255. animation: widget.iconAnimationController,
  256. builder: (BuildContext context, Widget child) {
  257. return Transform(
  258. transform: Matrix4.translationValues(
  259. (MediaQuery.of(context).size.width * 0.75 - 64) *
  260. (1.0 -
  261. widget.iconAnimationController.value -
  262. 1.0),
  263. 0.0,
  264. 0.0),
  265. child: Padding(
  266. padding: EdgeInsets.only(top: 8, bottom: 8),
  267. child: Container(
  268. width:
  269. MediaQuery.of(context).size.width * 0.75 - 64,
  270. height: 46,
  271. decoration: BoxDecoration(
  272. color: COLOR_CONST.DEFAULT.withOpacity(0.2),
  273. borderRadius: new BorderRadius.only(
  274. topLeft: Radius.circular(0),
  275. topRight: Radius.circular(28),
  276. bottomLeft: Radius.circular(0),
  277. bottomRight: Radius.circular(28),
  278. ),
  279. ),
  280. ),
  281. ),
  282. );
  283. },
  284. )
  285. : const SizedBox()
  286. ],
  287. ),
  288. ),
  289. );
  290. }
  291. Future<void> navigationtoScreen(DrawerIndex indexScreen) async {
  292. widget.callBackIndex(indexScreen);
  293. }
  294. _clickSignOut() {
  295. context.bloc<AuthenticationBloc>().add(AuthenticationLogoutRequested());
  296. }
  297. }
  298. enum DrawerIndex { ScanBarcode, Home, ControlDevice }
  299. class DrawerList {
  300. DrawerList({
  301. this.isAssetsImage = false,
  302. this.labelName = '',
  303. this.icon,
  304. this.index,
  305. this.imageName = '',
  306. });
  307. String labelName;
  308. Icon icon;
  309. bool isAssetsImage;
  310. String imageName;
  311. DrawerIndex index;
  312. }