import 'package:flutter/material.dart'; import 'package:flutter_tracker/dio/login_dao.dart'; import 'package:flutter_tracker/model/config.dart'; import 'package:flutter_tracker/model/message_model.dart'; import 'package:flutter_tracker/model/user_model.dart'; import 'package:flutter_tracker/routes/routes.dart'; import 'package:flutter_tracker/utils/app_util.dart'; import 'package:shared_preferences/shared_preferences.dart'; /// Description: /// Time : 2021年12月03日 Friday /// Author : liuyuqi.gov@msncn class MinePage extends StatefulWidget { const MinePage({Key key}) : super(key: key); @override _MinePageState createState() => _MinePageState(); } class _MinePageState extends State { Size get _size => MediaQuery.of(context).size; String _name = "张三"; int _health_status = 1; String _updateTime = "2021-11-25 10:10:10"; @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Color(0xE6E4E4), body: SizedBox( width: _size.width, child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( width: _size.width, color: Colors.blue, child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ const SizedBox( height: 50, ), // Container( // height: 100, // width: 100, // decoration: BoxDecoration( // borderRadius: BorderRadius.circular(50)), // child: Image.asset( // "assets/images/head.jpg", // ), // ), Text( _name, style: TextStyle(fontSize: 25), ), const SizedBox( height: 10, ), Text(_updateTime), const SizedBox( height: 10, ) ], ), ), const SizedBox( height: 10, ), Text("健康状态:"), buildImgStatus(), const SizedBox( height: 10, ), // Container( // width: _size.width * 0.9, // height: _size.width * 0.4, // decoration: BoxDecoration( // color: Colors.white, // borderRadius: BorderRadius.circular(20)), // child: Column( // crossAxisAlignment: CrossAxisAlignment.start, // children: [ // Container( // child: Text( // "更多", // style: TextStyle( // fontSize: 20, fontWeight: FontWeight.bold), // ), // margin: EdgeInsets.only(left: 10, top: 5), // ), // Row( // children: [ // Expanded( // child: InkWell( // onTap: () { // goSetting(); // }, // child: Column( // children: [ // SizedBox( // height: 10, // ), // Image.asset("assets/images/setting.png"), // const SizedBox( // height: 10, // ), // const Text("设置") // ], // ), // ), // ), // Expanded( // child: InkWell( // onTap: () { // aboutUs(); // }, // child: Column( // children: [ // SizedBox( // height: 10, // ), // Image.asset("assets/images/about.png"), // const SizedBox( // height: 10, // ), // const Text("关于我们") // ], // ), // ), // ), // ], // ), // ], // ), // ), Offstage( offstage: false, child: Container( width: 200, child: InkWell( onTap: () { goSubmit(); }, child: Container( width: double.infinity, height: 50, padding: EdgeInsets.only(right: 20, left: 20), decoration: BoxDecoration( gradient: const LinearGradient(colors: [ ThemeColor.subTextColor, ThemeColor.loignColor ]), borderRadius: BorderRadius.circular(10), boxShadow: const [ BoxShadow( offset: Offset(1.0, 5.0), color: ThemeColor.subTextColor, blurRadius: 5.0, ) ]), child: const Center( child: Text( "疫情上报", style: TextStyle(fontSize: 20, color: Colors.white), ), ), ), ), ), ), SizedBox( height: 50, ), Container( width: 150, child: InkWell( onTap: () { logout(); }, child: Container( width: double.infinity, height: 50, padding: EdgeInsets.only(right: 20, left: 20), decoration: BoxDecoration( gradient: const LinearGradient(colors: [ ThemeColor.loignColor, ThemeColor.loignColor ]), borderRadius: BorderRadius.circular(10), boxShadow: const [ BoxShadow( offset: Offset(1.0, 5.0), color: ThemeColor.loignColor, blurRadius: 5.0, ) ]), child: const Center( child: Text( "退出登录", style: TextStyle(fontSize: 20, color: Colors.white), ), ), ), ), ), ], ), ), ), ); } Widget buildImgStatus() { switch (_health_status) { case 1: return Image.asset( "assets/images/green.jpg", width: 200, height: 200, ); break; case 2: return Image.asset( "assets/images/red.jpg", width: 200, height: 200, ); break; case 3: return Image.asset( "assets/images/yellow.jpg", width: 200, height: 200, ); break; } } @override void initState() { super.initState(); getUserInfo(); } void getUserInfo() async { var sharedPreferences = await SharedPreferences.getInstance(); String token = sharedPreferences.getString("token"); UserEntity userEntity = await LoginDao.getUserInfo(token); if (userEntity.msg.success) { setState(() { _name = userEntity.user.username; _health_status = userEntity.user.healthStatus; _updateTime = userEntity.user.updateTime; }); } } void logout() async { var sharedPreferences = await SharedPreferences.getInstance(); String token = sharedPreferences.getString("token"); try { MessageModel messageModel = await LoginDao.logout(token); if (messageModel != null) { AppUtil.buildToast(messageModel.msg); } } catch (e) { AppUtil.buildToast("退出异常" + e.toString()); } Navigator.of(context).pushNamed(Routes.loginPage); sharedPreferences.remove("token"); sharedPreferences.setBool("isLogin", false); } void aboutUs() { AppUtil.buildToast("\"关于我们\"推出中.."); } void goSetting() { AppUtil.buildToast("\"设置\"推出中.."); } void goSubmit() { Navigator.of(context).pushNamed(Routes.submitPage); } }