me.dart 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import 'package:fast/constants.dart';
  2. import 'package:fast/model/model.dart';
  3. import 'package:fast/utils/api.dart';
  4. import 'package:fast/utils/global.dart';
  5. import 'package:fast/utils/http_utils.dart';
  6. import 'package:fast/utils/size_fit.dart';
  7. import 'package:fast/view/calendar.dart';
  8. import 'package:fast/view/component/header.dart';
  9. import 'package:fast/view/recharge.dart';
  10. import 'package:fast/view/setting.dart';
  11. import 'package:flutter/material.dart';
  12. import 'package:get/get.dart';
  13. import 'dart:convert' as convert;
  14. import 'package:shared_preferences/shared_preferences.dart';
  15. import 'balance_history.dart';
  16. class MePage extends StatefulWidget {
  17. const MePage({Key? key}) : super(key: key);
  18. @override
  19. State<MePage> createState() => _MePageState();
  20. }
  21. class _MePageState extends State<MePage> with RouteAware {
  22. late UserBean userBean;
  23. @override
  24. void initState() {
  25. userBean = Global().userBean!;
  26. super.initState();
  27. }
  28. @override
  29. void didChangeDependencies() {
  30. super.didChangeDependencies();
  31. Global().routeObserver!.subscribe(this, ModalRoute.of(context)!);
  32. }
  33. @override
  34. void didPopNext() {
  35. getUserInfo();
  36. super.didPopNext();
  37. }
  38. Future getUserInfo() async {
  39. if (mounted) {
  40. final prefs = await SharedPreferences.getInstance();
  41. String? temp = prefs.getString('userInfo');
  42. if (temp != null) {
  43. Map<String, dynamic> data = convert.jsonDecode(temp);
  44. UserBean bean = UserBean.fromJson(data);
  45. setState(() {
  46. userBean = bean;
  47. });
  48. }
  49. }
  50. }
  51. @override
  52. Widget build(BuildContext context) {
  53. SizeFit.initialize(context);
  54. var size = MediaQuery.of(context).size;
  55. bool isNight = false;
  56. DateTime now = DateTime.now();
  57. if (now.hour >= 18 || now.hour < 6) {
  58. isNight = true;
  59. }
  60. return SizedBox(
  61. width: double.infinity,
  62. height: double.infinity,
  63. child: Column(
  64. children: [
  65. Stack(
  66. children: [
  67. Header(
  68. isIndexPage: false,
  69. ),
  70. Container(
  71. padding: EdgeInsets.fromLTRB(24.px, size.height<=667?50.px:68.px, 24.px, 0),
  72. height: size.height<=667?162.px:180.px,
  73. child: Row(
  74. mainAxisAlignment: MainAxisAlignment.start,
  75. crossAxisAlignment: CrossAxisAlignment.start,
  76. children: [
  77. ClipOval(
  78. child: Image.network(
  79. userBean.avatar!,
  80. width: 64.px,
  81. height: 64.px,
  82. fit: BoxFit.cover,
  83. ),
  84. ),
  85. SizedBox(
  86. width: 10.px,
  87. ),
  88. Column(
  89. mainAxisAlignment: MainAxisAlignment.start,
  90. crossAxisAlignment: CrossAxisAlignment.start,
  91. children: [
  92. Text(
  93. userBean.nickname!,
  94. textAlign: TextAlign.left,
  95. style: TextStyle(
  96. color: isNight
  97. ? Colors.white
  98. : const Color(0xFF000D1F),
  99. fontSize: 20.px,
  100. fontWeight: FontWeight.bold),
  101. ),
  102. SizedBox(
  103. height: 6.px,
  104. ),
  105. Row(
  106. children: [
  107. Container(
  108. height: 24.px,
  109. padding: EdgeInsets.only(
  110. left: 9.px, right: 9.px),
  111. decoration: BoxDecoration(
  112. borderRadius: BorderRadius.all(
  113. Radius.circular(12.px)),
  114. border: Border.all(
  115. color: const Color(0x80FFFFFF),
  116. width: 1.px),
  117. color: const Color(0x33000D1F)),
  118. child: Row(
  119. children: [
  120. Text(
  121. '逆龄石',
  122. style: TextStyle(
  123. color: Colors.white,
  124. fontSize: 12.px),
  125. ),
  126. SizedBox(
  127. width: 2.px,
  128. ),
  129. Image.asset(
  130. 'assets/images/stone.png',
  131. width: 16.px,
  132. height: 16.px,
  133. ),
  134. SizedBox(
  135. width: 2.px,
  136. ),
  137. Text(
  138. '×${userBean.rjvBalance}',
  139. style: TextStyle(
  140. color: kThemeColor,
  141. fontSize: 14.px,
  142. fontFamily: 'Exo2',
  143. fontWeight: FontWeight.w600),
  144. ),
  145. Container(
  146. width: 1.px,
  147. height: 14.px,
  148. margin: EdgeInsets.only(left: 6.px,right: 6.px),
  149. color: const Color(0x80FFFFFF),
  150. ),
  151. GestureDetector(onTap: (){
  152. Get.to(() => const Recharge());
  153. },
  154. child: Text('去充值',style: TextStyle(color: Colors.white,fontSize: 10.px),),
  155. )
  156. ],
  157. ),
  158. ),
  159. GestureDetector(
  160. onTap: () {
  161. Get.to(() => const Setting());
  162. },
  163. child: Container(
  164. width: 24.px,
  165. height: 24.px,
  166. margin: EdgeInsets.only(left: 10.px),
  167. alignment: Alignment.center,
  168. child: Image.asset(
  169. 'assets/images/setting.png',
  170. width: 16.px,
  171. height: 16.px,
  172. ),
  173. decoration: BoxDecoration(
  174. color: const Color(0x33000D1F),
  175. borderRadius: BorderRadius.all(
  176. Radius.circular(12.px)),
  177. border: Border.all(
  178. color: const Color(0x80FFFFFF),
  179. width: 1.px)),
  180. ),
  181. )
  182. ],
  183. )
  184. ])
  185. ],
  186. ),
  187. )
  188. ],
  189. ),
  190. const Expanded(child: Calendar())
  191. ],
  192. ),
  193. );
  194. }
  195. }