mine_page.dart 9.0 KB

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