mine_page.dart 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_tracker/dio/login_dao.dart';
  3. import 'package:flutter_tracker/model/config.dart';
  4. import 'package:flutter_tracker/model/message_model.dart';
  5. import 'package:flutter_tracker/model/user_model.dart';
  6. import 'package:flutter_tracker/routes/routes.dart';
  7. import 'package:flutter_tracker/utils/app_util.dart';
  8. import 'package:shared_preferences/shared_preferences.dart';
  9. /// Description:
  10. /// Time : 2021年12月03日 Friday
  11. /// Author : liuyuqi.gov@msncn
  12. class MinePage extends StatefulWidget {
  13. const MinePage({Key key}) : super(key: key);
  14. @override
  15. _MinePageState createState() => _MinePageState();
  16. }
  17. class _MinePageState extends State<MinePage> {
  18. Size get _size => MediaQuery.of(context).size;
  19. String _name = "张三";
  20. int _health_status = 1;
  21. String _updateTime = "2021-11-25 10:10:10";
  22. @override
  23. Widget build(BuildContext context) {
  24. return Scaffold(
  25. backgroundColor: Color(0xE6E4E4),
  26. body: SizedBox(
  27. width: _size.width,
  28. child: SingleChildScrollView(
  29. child: Column(
  30. crossAxisAlignment: CrossAxisAlignment.center,
  31. children: [
  32. Container(
  33. width: _size.width,
  34. color: Colors.blue,
  35. child: Column(
  36. crossAxisAlignment: CrossAxisAlignment.center,
  37. children: [
  38. const SizedBox(
  39. height: 50,
  40. ),
  41. // Container(
  42. // height: 100,
  43. // width: 100,
  44. // decoration: BoxDecoration(
  45. // borderRadius: BorderRadius.circular(50)),
  46. // child: Image.asset(
  47. // "assets/images/head.jpg",
  48. // ),
  49. // ),
  50. Text(
  51. _name,
  52. style: TextStyle(fontSize: 25),
  53. ),
  54. const SizedBox(
  55. height: 10,
  56. ),
  57. Text(_updateTime),
  58. const SizedBox(
  59. height: 10,
  60. )
  61. ],
  62. ),
  63. ),
  64. const SizedBox(
  65. height: 10,
  66. ),
  67. Text("健康状态:"),
  68. buildImgStatus(),
  69. const SizedBox(
  70. height: 10,
  71. ),
  72. // Container(
  73. // width: _size.width * 0.9,
  74. // height: _size.width * 0.4,
  75. // decoration: BoxDecoration(
  76. // color: Colors.white,
  77. // borderRadius: BorderRadius.circular(20)),
  78. // child: Column(
  79. // crossAxisAlignment: CrossAxisAlignment.start,
  80. // children: [
  81. // Container(
  82. // child: Text(
  83. // "更多",
  84. // style: TextStyle(
  85. // fontSize: 20, fontWeight: FontWeight.bold),
  86. // ),
  87. // margin: EdgeInsets.only(left: 10, top: 5),
  88. // ),
  89. // Row(
  90. // children: [
  91. // Expanded(
  92. // child: InkWell(
  93. // onTap: () {
  94. // goSetting();
  95. // },
  96. // child: Column(
  97. // children: [
  98. // SizedBox(
  99. // height: 10,
  100. // ),
  101. // Image.asset("assets/images/setting.png"),
  102. // const SizedBox(
  103. // height: 10,
  104. // ),
  105. // const Text("设置")
  106. // ],
  107. // ),
  108. // ),
  109. // ),
  110. // Expanded(
  111. // child: InkWell(
  112. // onTap: () {
  113. // aboutUs();
  114. // },
  115. // child: Column(
  116. // children: [
  117. // SizedBox(
  118. // height: 10,
  119. // ),
  120. // Image.asset("assets/images/about.png"),
  121. // const SizedBox(
  122. // height: 10,
  123. // ),
  124. // const Text("关于我们")
  125. // ],
  126. // ),
  127. // ),
  128. // ),
  129. // ],
  130. // ),
  131. // ],
  132. // ),
  133. // ),
  134. Offstage(
  135. offstage: false,
  136. child: Container(
  137. width: 200,
  138. child: InkWell(
  139. onTap: () {
  140. goSubmit();
  141. },
  142. child: Container(
  143. width: double.infinity,
  144. height: 50,
  145. padding: EdgeInsets.only(right: 20, left: 20),
  146. decoration: BoxDecoration(
  147. gradient: const LinearGradient(colors: [
  148. ThemeColor.subTextColor,
  149. ThemeColor.loignColor
  150. ]),
  151. borderRadius: BorderRadius.circular(10),
  152. boxShadow: const [
  153. BoxShadow(
  154. offset: Offset(1.0, 5.0),
  155. color: ThemeColor.subTextColor,
  156. blurRadius: 5.0,
  157. )
  158. ]),
  159. child: const Center(
  160. child: Text(
  161. "疫情上报",
  162. style: TextStyle(fontSize: 20, color: Colors.white),
  163. ),
  164. ),
  165. ),
  166. ),
  167. ),
  168. ),
  169. SizedBox(
  170. height: 50,
  171. ),
  172. Container(
  173. width: 150,
  174. child: InkWell(
  175. onTap: () {
  176. logout();
  177. },
  178. child: Container(
  179. width: double.infinity,
  180. height: 50,
  181. padding: EdgeInsets.only(right: 20, left: 20),
  182. decoration: BoxDecoration(
  183. gradient: const LinearGradient(colors: [
  184. ThemeColor.loignColor,
  185. ThemeColor.loignColor
  186. ]),
  187. borderRadius: BorderRadius.circular(10),
  188. boxShadow: const [
  189. BoxShadow(
  190. offset: Offset(1.0, 5.0),
  191. color: ThemeColor.loignColor,
  192. blurRadius: 5.0,
  193. )
  194. ]),
  195. child: const Center(
  196. child: Text(
  197. "退出登录",
  198. style: TextStyle(fontSize: 20, color: Colors.white),
  199. ),
  200. ),
  201. ),
  202. ),
  203. ),
  204. ],
  205. ),
  206. ),
  207. ),
  208. );
  209. }
  210. Widget buildImgStatus() {
  211. switch (_health_status) {
  212. case 1:
  213. return Image.asset(
  214. "assets/images/green.jpg",
  215. width: 200,
  216. height: 200,
  217. );
  218. break;
  219. case 2:
  220. return Image.asset(
  221. "assets/images/red.jpg",
  222. width: 200,
  223. height: 200,
  224. );
  225. break;
  226. case 3:
  227. return Image.asset(
  228. "assets/images/yellow.jpg",
  229. width: 200,
  230. height: 200,
  231. );
  232. break;
  233. }
  234. }
  235. @override
  236. void initState() {
  237. super.initState();
  238. getUserInfo();
  239. }
  240. void getUserInfo() async {
  241. var sharedPreferences = await SharedPreferences.getInstance();
  242. String token = sharedPreferences.getString("token");
  243. UserEntity userEntity = await LoginDao.getUserInfo(token);
  244. if (userEntity.msg.success) {
  245. setState(() {
  246. _name = userEntity.user.username;
  247. _health_status = userEntity.user.healthStatus;
  248. _updateTime = userEntity.user.updateTime;
  249. });
  250. }
  251. }
  252. void logout() async {
  253. var sharedPreferences = await SharedPreferences.getInstance();
  254. String token = sharedPreferences.getString("token");
  255. try {
  256. MessageModel messageModel = await LoginDao.logout(token);
  257. if (messageModel != null) {
  258. AppUtil.buildToast(messageModel.msg);
  259. }
  260. } catch (e) {
  261. AppUtil.buildToast("退出异常" + e.toString());
  262. }
  263. Navigator.of(context).pushNamed(Routes.loginPage);
  264. sharedPreferences.remove("token");
  265. sharedPreferences.setBool("isLogin", false);
  266. }
  267. void aboutUs() {
  268. AppUtil.buildToast("\"关于我们\"推出中..");
  269. }
  270. void goSetting() {
  271. AppUtil.buildToast("\"设置\"推出中..");
  272. }
  273. void goSubmit() {
  274. Navigator.of(context).pushNamed(Routes.submitPage);
  275. }
  276. }