YSUserInfo.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:shared_preferences/shared_preferences.dart';
  5. import 'package:sy_flutter_qiniu_storage/sy_flutter_qiniu_storage.dart';
  6. import 'package:ysairplane/base/YSBase.dart';
  7. import 'package:ysairplane/code/YSCity.dart';
  8. import 'package:ysairplane/tools/YSNetWorking.dart';
  9. import 'package:ysairplane/tools/YSTools.dart';
  10. import 'package:image_picker/image_picker.dart';
  11. class YSUserInfo extends StatefulWidget {
  12. @override
  13. _YSUserInfoState createState() => _YSUserInfoState();
  14. }
  15. class _YSUserInfoState extends State<YSUserInfo> {
  16. ImagePicker _picker = ImagePicker();
  17. List array = [{'title':'头像','content':''},{'title':'真实姓名','content':'请输入真实姓名'},{'title':'性别','content':'请选择性别'},
  18. {'title':'地区','content':'请选择地区'},{'title':'登录手机','content':''},
  19. {'title':'邮箱地址','content':'请输入邮箱地址'},{'title':'绑定微信','content':''},{'title':'绑定支付宝','content':''},
  20. {'title':'公司名称','content':'请输入公司名称'},{'title':'公司职务','content':'请输入职务'},
  21. {'title':'公司行业','content':'请输入行业'},{'title':'网址','content':'请输入网址'},{'title':'所在地区','content':'请选择公司所在地区'}];
  22. List chooses = ['男','女'];
  23. String _phone = '';
  24. String _avatar;
  25. String _tokenStr = '';
  26. String _urlStr = '';
  27. @override
  28. void initState() {
  29. Future.delayed(Duration(seconds: 0)).then((value){
  30. _getQiNiuTokenData();
  31. });
  32. super.initState();
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return YSBase(
  37. ystitle: '个人资料',
  38. yschild: Container(
  39. height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44,
  40. width: MediaQuery.of(context).size.width,
  41. color: Color(0xFFF5F6F8),
  42. child: ListView.separated(
  43. itemBuilder: (context,index){
  44. return GestureDetector(
  45. onTap: (){
  46. if(index==0){
  47. showCupertinoModalPopup(
  48. context: context,
  49. builder: (context) {
  50. return CupertinoActionSheet(
  51. actions: <Widget>[
  52. CupertinoActionSheetAction(
  53. child: Text('拍摄照片'),
  54. onPressed: () {
  55. Navigator.pop(context);
  56. _picker.getImage(source: ImageSource.camera,imageQuality: 50).then((value){
  57. _onUpload(value);
  58. });
  59. },
  60. ),
  61. CupertinoActionSheetAction(
  62. child: Text('选择图片'),
  63. onPressed: () {
  64. Navigator.pop(context);
  65. _picker.getImage(source: ImageSource.gallery,imageQuality: 50).then((value){
  66. _onUpload(value);
  67. });
  68. },
  69. ),
  70. ],
  71. cancelButton: CupertinoActionSheetAction(
  72. child: Text('取消'),
  73. onPressed: () {
  74. Navigator.pop(context);
  75. },
  76. ),
  77. );
  78. }
  79. );
  80. }else if(index==6||index==7||index==3||index==12){
  81. if(index==3||index==12){
  82. Navigator.of(context).push(
  83. CupertinoPageRoute(builder: (context){
  84. return YSCity();
  85. })
  86. ).then((value){
  87. if(value!=null){
  88. }
  89. });
  90. }else{
  91. }
  92. }else if(index==1||index==5||index==8||index==9||index==10||index==11){
  93. Navigator.push(context, PopRoute(child: BottomInputDialog(
  94. height: 185,
  95. color: Colors.white,
  96. inputView: Column(
  97. children: [
  98. Container(
  99. padding: EdgeInsets.only(top: 5,bottom: 10,left: 10),
  100. child: Row(
  101. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  102. children: [
  103. Text(index==1?'真实姓名':index==5?'邮箱地址':index==8?'公司名称':index==9?'公司职务':index==10?'公司行业':'网址',
  104. style: TextStyle(fontSize: 14,color: Color(0xFF000000),decoration: TextDecoration.none,fontWeight: FontWeight.bold),),
  105. Icon(Icons.close,size: 20,color: Color(0xFF9A9A9A),)
  106. ],
  107. ),
  108. ),
  109. Container(
  110. height: 50,
  111. width: MediaQuery.of(context).size.width-30,
  112. child: CupertinoTextField(
  113. placeholder: '请输入',
  114. style: TextStyle(fontSize: 15,color: Color(0xFF9A9A9A),decoration: TextDecoration.none,fontWeight: FontWeight.normal,),
  115. placeholderStyle: TextStyle(fontSize: 15,color: Color(0xFF9A9A9A),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  116. autofocus: true,
  117. decoration: BoxDecoration(),
  118. maxLines: 10,
  119. ),
  120. decoration: BoxDecoration(
  121. border: Border(bottom: BorderSide(color: Color(0xFFF5F6F8),width: 0.5))
  122. ),
  123. margin: EdgeInsets.only(top: 10),
  124. ),
  125. Container(
  126. margin: EdgeInsets.all(15),
  127. height: 40,
  128. width: MediaQuery.of(context).size.width-40,
  129. alignment: Alignment.center,
  130. decoration: BoxDecoration(
  131. color: Color(0xFF007AFF),
  132. borderRadius: BorderRadius.all(Radius.circular(6))
  133. ),
  134. child: Text('完成',style: TextStyle(fontSize: 17,color: Colors.white,fontWeight: FontWeight.bold,decoration: TextDecoration.none),),
  135. )
  136. ],
  137. ),
  138. )));
  139. }else{
  140. }
  141. },
  142. child: Container(
  143. height: 50,
  144. color: Colors.white,
  145. padding: EdgeInsets.only(left: 15,right: 15),
  146. child: Row(
  147. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  148. children: [
  149. Text('${array[index]['title']}',style: TextStyle(fontSize: 16,color: Color(0xFF000000)),),
  150. index==0?Container(
  151. height: 40,
  152. width: 40,
  153. decoration: BoxDecoration(
  154. borderRadius: BorderRadius.all(Radius.circular(20)),
  155. color: Colors.black12
  156. ),
  157. child: _avatar!=null?ClipRRect(
  158. borderRadius: BorderRadius.all(Radius.circular(20)),
  159. child: CachedNetworkImage(
  160. imageUrl: _avatar,
  161. fit: BoxFit.fill,
  162. ),
  163. ):Container(),
  164. ):index==6||index==7||index==3||index==12?Row(
  165. children: [
  166. Text('${array[index]['content']}',style: TextStyle(fontSize: 16,color: Color(0xFF9A9A9A)),),
  167. Icon(Icons.keyboard_arrow_right,size: 20,color: Color(0xFF9A9A9A),)
  168. ],
  169. ):index==1||index==4||index==5||index==8||index==9||index==10||index==11?Text(
  170. index==4?_phone:'${array[index]['content']}',
  171. style: TextStyle(fontSize: 16,color: Color(0xFF9A9A9A)),
  172. ):DropdownButton(
  173. value: '${chooses[0]}',
  174. items: [
  175. for(int i=0;i<chooses.length;i++)DropdownMenuItem(child: Text('${chooses[i]}'),value: '${chooses[i]}',),
  176. ],
  177. onChanged: (value){
  178. },
  179. underline: Container(),
  180. icon: Icon(Icons.keyboard_arrow_down,size: 20,color: Color(0xFF999999),),
  181. style: TextStyle(fontSize: 15,color: Color(0xFF999999)),
  182. )
  183. ],
  184. ),
  185. ),
  186. );
  187. },
  188. separatorBuilder: (context,index){
  189. return Container(
  190. color: Color(0xFFF5F6F8),
  191. height: index==3||index==7?10:0.5,
  192. );
  193. },
  194. itemCount: array.length,
  195. padding: EdgeInsets.only(top: 10,bottom: 30),
  196. ),
  197. ),
  198. );
  199. }
  200. _postEditUserData(var request) async{
  201. Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/applets/center/info/update',parameter: request,isLoading: false,
  202. isToken: true,refresh: (){_postEditUserData(request);});
  203. if(dict!=null){
  204. setState(() {
  205. });
  206. }
  207. }
  208. _onUpload(var value) async {
  209. if (value == null) {
  210. return;
  211. }
  212. print(value.path);
  213. print(_tokenStr);
  214. final syStorage = new SyFlutterQiniuStorage();
  215. //监听上传进度
  216. syStorage.onChanged().listen((dynamic percent) {
  217. print(percent);
  218. });
  219. //上传文件
  220. var result = await syStorage.upload(value.path, _tokenStr, DateTime.now().millisecondsSinceEpoch.toString() +'.' +value.path.split('.').last);
  221. if(result.success==true){
  222. _postEditUserData({'avatar':_urlStr+'${result.result['key']}'});
  223. }
  224. print(result);
  225. }
  226. _getQiNiuTokenData() async{
  227. SharedPreferences prefer = await SharedPreferences.getInstance();
  228. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/getToken',parameter: {},isLoading: false,isToken: false);
  229. if(dict!=null){
  230. _phone = prefer.getString('phone');
  231. _avatar = prefer.getString('avatar');
  232. _tokenStr = dict['token'];
  233. _urlStr = dict['prefix'];
  234. setState(() {
  235. });
  236. }
  237. }
  238. }