menu.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_svg/svg.dart';
  3. import 'package:get/get.dart';
  4. import 'package:link/utils/global.dart';
  5. import 'package:link/utils/storage.dart';
  6. import 'package:link/view/component/toast.dart';
  7. import '../../utils/size_fit.dart';
  8. import 'link_btn.dart';
  9. class Menu extends StatefulWidget {
  10. bool enable = true;
  11. var close;
  12. Menu({Key? key, bool? isEnable, var closeMenu}) : super(key: key) {
  13. if (isEnable != null) {
  14. enable = isEnable;
  15. }
  16. if (closeMenu != null) {
  17. close = closeMenu;
  18. }
  19. }
  20. @override
  21. State<Menu> createState() => _MenuState();
  22. }
  23. class _MenuState extends State<Menu> {
  24. logoutAlert() {
  25. return Container(
  26. alignment: Alignment.center,
  27. padding: EdgeInsets.only(top: 32.px, bottom: 32.px),
  28. child: Column(
  29. children: [
  30. SvgPicture.asset(
  31. 'assets/icons/question.svg',
  32. width: 48.px,
  33. height: 48.px,
  34. ),
  35. SizedBox(
  36. height: 12.px,
  37. ),
  38. Text(
  39. '确定要退出当前账号吗?',
  40. textAlign: TextAlign.center,
  41. style: TextStyle(
  42. color: Colors.white,
  43. fontSize: 16.px,
  44. fontWeight: FontWeight.bold),
  45. ),
  46. SizedBox(
  47. height: 16.px,
  48. ),
  49. AlertButton(
  50. title: '立即退出',
  51. isCancel: false,
  52. width: 220.px,
  53. height: 40.px,
  54. callback: () {
  55. Toast().hideHud();
  56. widget.close();
  57. StorageUtil().clearAll();
  58. Global().token = '';
  59. Global().hasLogin = false;
  60. Get.toNamed('/welcome');
  61. }),
  62. SizedBox(
  63. height: 24.px,
  64. ),
  65. AlertButton(
  66. title: '取消',
  67. isCancel: true,
  68. width: 220.px,
  69. height: 40.px,
  70. callback: () {
  71. Toast().hideHud();
  72. }),
  73. ],
  74. ),
  75. );
  76. }
  77. logout() {
  78. if (widget.enable == false) {
  79. return;
  80. }
  81. Toast().showCustomHud(logoutAlert(), context: context);
  82. }
  83. tapItem(i) {
  84. if (!widget.enable) {
  85. return;
  86. }
  87. switch (i) {
  88. case 0:
  89. Get.toNamed('/choose_theme');
  90. break;
  91. case 1:
  92. Get.toNamed('/edit_info');
  93. break;
  94. case 2:
  95. Get.toNamed('/account');
  96. break;
  97. case 3:
  98. Get.toNamed('/history');
  99. break;
  100. }
  101. widget.close();
  102. }
  103. @override
  104. Widget build(BuildContext context) {
  105. SizeFit.initialize(context);
  106. List items = [
  107. {'name': '主题风格', 'icon': 'assets/icons/theme.svg'},
  108. {'name': '基本信息', 'icon': 'assets/icons/base_info.svg'},
  109. {'name': '账号安全', 'icon': 'assets/icons/safe.svg'},
  110. {'name': '访问历史', 'icon': 'assets/icons/history.svg'}
  111. ];
  112. return Container(
  113. width: 120.px,
  114. color: const Color(0xE6000000),
  115. alignment: Alignment.topLeft,
  116. child: Stack(children: [
  117. SizedBox(
  118. width: 120.px,
  119. ),
  120. Positioned(
  121. left: 24.px,
  122. top: 24.px,
  123. child: GestureDetector(
  124. onTap: () {
  125. if (widget.enable) {
  126. widget.close();
  127. }
  128. },
  129. child: SvgPicture.asset(
  130. 'assets/icons/close.svg',
  131. width: 24.px,
  132. height: 24.px,
  133. ),
  134. )),
  135. Column(
  136. children: [
  137. SizedBox(
  138. width: 120.px,
  139. height: 84.px,
  140. ),
  141. ...List<Widget>.generate(items.length, (i) {
  142. return Container(
  143. margin: EdgeInsets.only(bottom: 36.px),
  144. child: GestureDetector(
  145. onTap: () {
  146. tapItem(i);
  147. },
  148. child: Column(
  149. children: [
  150. SvgPicture.asset(
  151. items[i]['icon'],
  152. width: 36.px,
  153. height: 36.px,
  154. ),
  155. SizedBox(
  156. height: 8.px,
  157. ),
  158. Text(
  159. items[i]['name'],
  160. style: TextStyle(color: Colors.white, fontSize: 14.px),
  161. )
  162. ],
  163. ),
  164. ),
  165. );
  166. }),
  167. Expanded(child: Container()),
  168. GestureDetector(
  169. onTap: () {
  170. logout();
  171. },
  172. child: Text(
  173. '退出登录',
  174. style: TextStyle(color: Colors.white, fontSize: 14.px),
  175. ),
  176. ),
  177. SizedBox(
  178. height: 12.px,
  179. ),
  180. Text(
  181. 'v1.0.0',
  182. style: TextStyle(color: const Color(0xFF444447), fontSize: 12.px),
  183. ),
  184. SizedBox(
  185. height: 24.px,
  186. ),
  187. ],
  188. )
  189. ]),
  190. );
  191. }
  192. }