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.

281 lines
9.3KB

  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. Column(
  130. children: <Widget>[
  131. ListTile(
  132. title: Text(
  133. 'Đăng xuất',
  134. style: TextStyle(
  135. fontWeight: FontWeight.w600,
  136. fontSize: 16,
  137. ),
  138. textAlign: TextAlign.left,
  139. ),
  140. trailing: Icon(
  141. Icons.power_settings_new,
  142. color: Colors.red,
  143. ),
  144. onTap: () {
  145. _clickSignOut();
  146. },
  147. ),
  148. SizedBox(
  149. height: MediaQuery.of(context).padding.bottom,
  150. )
  151. ],
  152. ),
  153. ],
  154. ),
  155. );
  156. }
  157. Widget inkwell(DrawerList listData) {
  158. return Material(
  159. color: Colors.white,
  160. child: InkWell(
  161. splashColor: Colors.grey.withOpacity(0.1),
  162. highlightColor: Colors.transparent,
  163. onTap: () {
  164. navigationtoScreen(listData.index);
  165. },
  166. child: Stack(
  167. children: <Widget>[
  168. Container(
  169. padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
  170. child: Row(
  171. children: <Widget>[
  172. Container(
  173. width: 6.0,
  174. height: 46.0,
  175. ),
  176. const Padding(
  177. padding: EdgeInsets.all(4.0),
  178. ),
  179. listData.isAssetsImage
  180. ? Container(
  181. width: 24,
  182. height: 24,
  183. child: Image.asset(listData.imageName,
  184. color: widget.screenIndex == listData.index
  185. ? COLOR_CONST.DEFAULT
  186. : COLOR_CONST.BLACK),
  187. )
  188. : Icon(listData.icon.icon,
  189. color: widget.screenIndex == listData.index
  190. ? COLOR_CONST.DEFAULT
  191. : COLOR_CONST.BLACK),
  192. const Padding(
  193. padding: EdgeInsets.all(4.0),
  194. ),
  195. Text(
  196. listData.labelName,
  197. style: TextStyle(
  198. fontWeight: FontWeight.w500,
  199. fontSize: 16,
  200. color: widget.screenIndex == listData.index
  201. ? COLOR_CONST.DEFAULT
  202. : COLOR_CONST.BLACK,
  203. ),
  204. textAlign: TextAlign.left,
  205. ),
  206. ],
  207. ),
  208. ),
  209. widget.screenIndex == listData.index
  210. ? AnimatedBuilder(
  211. animation: widget.iconAnimationController,
  212. builder: (BuildContext context, Widget child) {
  213. return Transform(
  214. transform: Matrix4.translationValues(
  215. (MediaQuery.of(context).size.width * 0.75 - 64) *
  216. (1.0 -
  217. widget.iconAnimationController.value -
  218. 1.0),
  219. 0.0,
  220. 0.0),
  221. child: Padding(
  222. padding: EdgeInsets.only(top: 8, bottom: 8),
  223. child: Container(
  224. width:
  225. MediaQuery.of(context).size.width * 0.75 - 64,
  226. height: 46,
  227. decoration: BoxDecoration(
  228. color: COLOR_CONST.DEFAULT.withOpacity(0.2),
  229. borderRadius: new BorderRadius.only(
  230. topLeft: Radius.circular(0),
  231. topRight: Radius.circular(28),
  232. bottomLeft: Radius.circular(0),
  233. bottomRight: Radius.circular(28),
  234. ),
  235. ),
  236. ),
  237. ),
  238. );
  239. },
  240. )
  241. : const SizedBox()
  242. ],
  243. ),
  244. ),
  245. );
  246. }
  247. Future<void> navigationtoScreen(DrawerIndex indexScreen) async {
  248. widget.callBackIndex(indexScreen);
  249. }
  250. _clickSignOut() {
  251. context.bloc<AuthenticationBloc>().add(AuthenticationLogoutRequested());
  252. }
  253. }
  254. enum DrawerIndex { ScanBarcode, Home, Setting }
  255. class DrawerList {
  256. DrawerList({
  257. this.isAssetsImage = false,
  258. this.labelName = '',
  259. this.icon,
  260. this.index,
  261. this.imageName = '',
  262. });
  263. String labelName;
  264. Icon icon;
  265. bool isAssetsImage;
  266. String imageName;
  267. DrawerIndex index;
  268. }