mine_page.dart 9.1 KB

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