account.dart 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import '../constants.dart';
  4. import '../utils/api.dart';
  5. import '../utils/global.dart';
  6. import '../utils/http_utils.dart';
  7. import '../utils/size_fit.dart';
  8. import 'component/top_container.dart';
  9. class Account extends StatefulWidget {
  10. const Account({Key? key}) : super(key: key);
  11. @override
  12. State<Account> createState() => _AccountState();
  13. }
  14. class _AccountState extends State<Account> with RouteAware {
  15. String email = '', phone = '';
  16. bool isBindPhone = false;
  17. @override
  18. void initState() {
  19. // TODO: implement initState
  20. getUserInfo();
  21. super.initState();
  22. }
  23. @override
  24. void didChangeDependencies() {
  25. // TODO: implement didChangeDependencies
  26. super.didChangeDependencies();
  27. Global().routeObserver!.subscribe(this, ModalRoute.of(context)!);
  28. }
  29. @override
  30. void didPopNext() {
  31. // TODO: implement didPopNext
  32. getUserInfo();
  33. super.didPopNext();
  34. }
  35. Future getUserInfo() async {
  36. var data = await HttpUtils.get(Api.userInfo);
  37. setState(() {
  38. if (data['email'] != null) {
  39. email = data['email'];
  40. }
  41. if (data['mobile_bind']) {
  42. isBindPhone = true;
  43. }
  44. phone = data['mobile'];
  45. });
  46. }
  47. @override
  48. Widget build(BuildContext context) {
  49. SizeFit.initialize(context);
  50. TextStyle textStyle = TextStyle(
  51. color: Colors.white, fontSize: 16.px, fontWeight: FontWeight.bold);
  52. return Material(
  53. color: kBgColor,
  54. child: TopContainer(
  55. child: Stack(children: [
  56. Column(children: [
  57. Container(
  58. width: 343.px,
  59. margin: EdgeInsets.only(top: 16.px),
  60. padding: EdgeInsets.all(20.px),
  61. decoration: BoxDecoration(
  62. color: const Color(0xFF2C2C2E),
  63. borderRadius: BorderRadius.circular(24.px)),
  64. child: Column(
  65. children: [
  66. GestureDetector(
  67. onTap: () {
  68. if (!isBindPhone) {
  69. Get.toNamed('/bind', parameters: {'type': 'sms'});
  70. }
  71. },
  72. child: Row(
  73. children: [
  74. Image.asset(
  75. 'assets/images/bind_phone.png',
  76. width: 24.px,
  77. height: 24.px,
  78. ),
  79. SizedBox(
  80. width: 8.px,
  81. ),
  82. Expanded(
  83. child: Text(
  84. '手机',
  85. style: textStyle,
  86. )),
  87. Text(
  88. isBindPhone ? phone : '立即绑定',
  89. style: TextStyle(
  90. color: isBindPhone
  91. ? const Color(0xFF74747A)
  92. : kBtnColor,
  93. fontSize: 14.px),
  94. )
  95. ],
  96. ),
  97. ),
  98. Container(
  99. height: 1.px,
  100. color: const Color(0xFF404040),
  101. margin: EdgeInsets.only(top: 18.px, bottom: 18.px),
  102. ),
  103. GestureDetector(
  104. onTap: (() {
  105. if (email.isEmpty) {
  106. Get.toNamed('/bind', parameters: {'type': 'email'});
  107. }
  108. }),
  109. child: Row(
  110. children: [
  111. Image.asset(
  112. 'assets/images/bind_email.png',
  113. width: 24.px,
  114. height: 24.px,
  115. ),
  116. SizedBox(
  117. width: 8.px,
  118. ),
  119. Expanded(
  120. child: Text(
  121. '邮箱',
  122. style: textStyle,
  123. )),
  124. Text(
  125. email.isNotEmpty ? email : '立即绑定',
  126. style: TextStyle(
  127. color: email.isNotEmpty
  128. ? const Color(0xFF74747A)
  129. : kBtnColor,
  130. fontSize: 14.px),
  131. )
  132. ],
  133. ),
  134. ),
  135. ],
  136. ),
  137. ),
  138. Container(
  139. width: 343.px,
  140. margin: EdgeInsets.only(top: 16.px),
  141. padding: EdgeInsets.all(20.px),
  142. decoration: BoxDecoration(
  143. color: const Color(0xFF2C2C2E),
  144. borderRadius: BorderRadius.circular(24.px)),
  145. child: Column(
  146. children: [
  147. GestureDetector(
  148. onTap: (() {
  149. if (!isBindPhone) {
  150. Get.toNamed('/bind', parameters: {'type': 'sms'});
  151. }
  152. }),
  153. child: Row(
  154. children: [
  155. Image.asset(
  156. 'assets/images/bind_phone.png',
  157. width: 24.px,
  158. height: 24.px,
  159. ),
  160. SizedBox(
  161. width: 8.px,
  162. ),
  163. Expanded(
  164. child: Text(
  165. '微信',
  166. style: textStyle,
  167. )),
  168. Text(
  169. '立即绑定',
  170. style: TextStyle(color: kBtnColor, fontSize: 14.px),
  171. )
  172. ],
  173. ),
  174. ),
  175. Container(
  176. height: 1.px,
  177. color: const Color(0xFF404040),
  178. margin: EdgeInsets.only(top: 18.px, bottom: 18.px),
  179. ),
  180. GestureDetector(
  181. child: Row(
  182. children: [
  183. Image.asset(
  184. 'assets/images/bind_email.png',
  185. width: 24.px,
  186. height: 24.px,
  187. ),
  188. SizedBox(
  189. width: 8.px,
  190. ),
  191. Expanded(
  192. child: Text(
  193. 'QQ',
  194. style: textStyle,
  195. )),
  196. Text(
  197. '立即绑定',
  198. style: TextStyle(color: kBtnColor, fontSize: 14.px),
  199. )
  200. ],
  201. ),
  202. ),
  203. Container(
  204. height: 1.px,
  205. color: const Color(0xFF404040),
  206. margin: EdgeInsets.only(top: 18.px, bottom: 18.px),
  207. ),
  208. GestureDetector(
  209. child: Row(
  210. children: [
  211. Image.asset(
  212. 'assets/images/bind_email.png',
  213. width: 24.px,
  214. height: 24.px,
  215. ),
  216. SizedBox(
  217. width: 8.px,
  218. ),
  219. Expanded(
  220. child: Text(
  221. '微博',
  222. style: textStyle,
  223. )),
  224. Text(
  225. '立即绑定',
  226. style: TextStyle(color: kBtnColor, fontSize: 14.px),
  227. )
  228. ],
  229. ),
  230. ),
  231. ],
  232. ),
  233. ),
  234. ]),
  235. ])));
  236. }
  237. }