YSMine.dart 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_tzh/base/YSBase.dart';
  4. import 'package:flutter_tzh/mine/YSMineChangePassword.dart';
  5. import 'package:flutter_tzh/mine/YSMineGatherPlan.dart';
  6. import 'package:flutter_tzh/tool/YSAlertView.dart';
  7. import 'package:flutter_tzh/tool/YSFileView.dart';
  8. import 'package:flutter_tzh/tool/YSNetWork.dart';
  9. import 'package:shared_preferences/shared_preferences.dart';
  10. import '../login/YSLogin.dart';
  11. import '../tool/YSTools.dart';
  12. class YSMine extends StatefulWidget {
  13. const YSMine({Key? key}) : super(key: key);
  14. @override
  15. YSMineState createState() => YSMineState();
  16. }
  17. class YSMineState extends State<YSMine> {
  18. final List _menuArray = [
  19. {'image':'mine_menu1','title':'采集计划'},
  20. {'image':'mine_menu2','title':'修改密码'},
  21. {'image':'mine_menu3','title':'退出登陆'}
  22. ];
  23. Map _data = {};
  24. @override
  25. void initState() {
  26. networkDelay((){
  27. _getUserCenter();
  28. });
  29. super.initState();
  30. }
  31. _getUserCenter() async{
  32. YSNetWork.ysRequestHttp(context, type: RequestType.get, api: '/user/center', parameter: {}, successSetter: (dict){
  33. _data = dict['data']??{};
  34. setState(() {});
  35. });
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. return YSBase(
  40. ysTitle: '个人中心',
  41. isTab: true,
  42. ysChild: Column(
  43. children: [
  44. Container(
  45. decoration: BoxDecoration(
  46. color: const Color(0xFF2E3138),
  47. borderRadius: const BorderRadius.all(Radius.circular(24)),
  48. border: Border.all(color: const Color(0xFF3E434E),width: hsp(1))
  49. ),
  50. height: hsp(333),
  51. width: ysWidth(context)-hsp(40),
  52. margin: EdgeInsets.only(top: hsp(20)),
  53. child: Column(
  54. children: [
  55. Container(
  56. height: hsp(161),
  57. alignment: Alignment.center,
  58. decoration: BoxDecoration(
  59. border: Border.all(color: const Color(0xFF3E434E),width: hsp(1))
  60. ),
  61. child: Column(
  62. mainAxisSize: MainAxisSize.min,
  63. children: [
  64. Container(
  65. width: ysWidth(context)-hsp(140),
  66. height: hsp(100),
  67. decoration: const BoxDecoration(
  68. image: DecorationImage(image: AssetImage('images/mine_bg.png'))
  69. ),
  70. alignment: Alignment.center,
  71. child: GestureDetector(
  72. onLongPress: () async{
  73. bool isAgree = await permissionHandler('file');
  74. if(isAgree&&mounted){
  75. ysShowCenterAlertView(context, YSTipsAlertView(valueSetter: (value) {
  76. if(value){
  77. uploadFile(context, (value) async{
  78. // LogUtil.d(value['url']);
  79. YSNetWork.ysRequestHttp(context, type: RequestType.post, api: '/user/modify', parameter: {'avatar':value['url']}, successSetter: (dict){
  80. bool data = dict['data']??false;
  81. if(data){
  82. _getUserCenter();
  83. }
  84. });
  85. });
  86. }
  87. },tipsStr: '是否修改头像?',));
  88. }
  89. },
  90. child: Container(
  91. height: hsp(60),
  92. width: hsp(60),
  93. decoration: _data.isEmpty?const BoxDecoration(
  94. borderRadius: BorderRadius.all(Radius.circular(7)),
  95. color: Colors.white,
  96. ):BoxDecoration(
  97. borderRadius: const BorderRadius.all(Radius.circular(7)),
  98. color: Colors.white,
  99. image: DecorationImage(image: NetworkImage('$fileUrl${_data['avatar']}'),fit: BoxFit.fill)
  100. ),
  101. ),
  102. ),
  103. ),
  104. Container(
  105. padding: EdgeInsets.only(left: hsp(13),right: hsp(13),top: hsp(5),bottom: hsp(5)),
  106. decoration: const BoxDecoration(
  107. color: Color(0xFF23262B),
  108. borderRadius: BorderRadius.all(Radius.circular(2)),
  109. ),
  110. margin: EdgeInsets.only(bottom: hsp(3)),
  111. child: Text(_data['name']??'',style: TextStyle(fontSize: zsp(11),color: const Color(0xFF8A93A0),backgroundColor: const Color(0xFF23262B))),
  112. ),
  113. Container(
  114. height: hsp(20),
  115. padding: EdgeInsets.only(left: hsp(5),right: hsp(5)),
  116. child: Text(_data['phone']??'',style: TextStyle(fontSize: zsp(12),color: const Color(0xFFACB5C5)),),
  117. )
  118. ],
  119. ),
  120. ),
  121. SizedBox(
  122. height: hsp(170),
  123. child: ListView.separated(
  124. itemBuilder: (context, index) {
  125. Map item = _menuArray[index];
  126. return GestureDetector(
  127. onTap: (){
  128. if(item['title']=='采集计划'){
  129. Navigator.of(context).push(
  130. CupertinoPageRoute(builder: (context){
  131. return const YSMineGatherPlan();
  132. })
  133. );
  134. }else if(item['title']=='修改密码'){
  135. Navigator.of(context).push(
  136. CupertinoPageRoute(builder: (context){
  137. return const YSMineChangePassword();
  138. })
  139. );
  140. }else if(item['title']=='退出登陆'){
  141. ysShowCenterAlertView(context, YSTipsAlertView(
  142. valueSetter: (value) async{
  143. if(value){
  144. YSNetWork.ysRequestHttp(context, type: RequestType.get, api: '/auth/logout', parameter: {}, successSetter: (dict) async{
  145. SharedPreferences prefs = await SharedPreferences.getInstance();
  146. prefs.remove('token');
  147. if(!mounted)return;
  148. Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context){
  149. return const YSLogin();
  150. }), (route) => false);
  151. });
  152. }
  153. },
  154. tipsStr: '是否退出登录?',
  155. ));
  156. }
  157. },
  158. behavior: HitTestBehavior.opaque,
  159. child: SizedBox(
  160. height: hsp(40),
  161. child: Row(
  162. children: [
  163. Image.asset('images/${item['image']}.png',height: hsp(7),width: hsp(7),),
  164. Container(
  165. width: ysWidth(context)-hsp(80),
  166. padding: EdgeInsets.only(left: hsp(10)),
  167. child: Text(item['title'],style: TextStyle(fontSize: zsp(15),color: const Color(0xFFDBE1EA)),),
  168. )
  169. ],
  170. ),
  171. ),
  172. );
  173. },
  174. separatorBuilder: (context,index){
  175. return Container(height: hsp(12),);
  176. },
  177. itemCount: _menuArray.length,
  178. shrinkWrap: true,
  179. padding: EdgeInsets.only(top: hsp(12),left: hsp(15),right: hsp(15)),
  180. physics: const NeverScrollableScrollPhysics(),
  181. ),
  182. ),
  183. ],
  184. ),
  185. ),
  186. ],
  187. ),
  188. );
  189. }
  190. }