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.

277 lines
9.1KB

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