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.

285 lines
9.4KB

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