YSUserInfo.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  4. import 'package:flutterappfuyou/code/version2/YSChangePassWord.dart';
  5. import 'package:shared_preferences/shared_preferences.dart';
  6. import 'YSMeans.dart';
  7. import 'package:image_picker/image_picker.dart';
  8. import 'base/YSBase.dart';
  9. import 'base/YSTools.dart';
  10. class YSUserInfo extends StatefulWidget {
  11. @override
  12. _YSUserInfoState createState() => _YSUserInfoState();
  13. }
  14. class _YSUserInfoState extends State<YSUserInfo> {
  15. String name,avatar;
  16. final ImagePicker _picker = ImagePicker();
  17. @override
  18. void initState() {
  19. _getInfo();
  20. super.initState();
  21. }
  22. @override
  23. Widget build(BuildContext context) {
  24. return YSBase(
  25. ystitle: '个人信息',
  26. yschild: SingleChildScrollView(
  27. child: Column(
  28. children: [
  29. Container(
  30. width: MediaQuery.of(context).size.width-10,
  31. height: 100,
  32. margin: EdgeInsets.only(top: 5),
  33. decoration: BoxDecoration(
  34. color: Colors.white,
  35. borderRadius: BorderRadius.all(Radius.circular(6))
  36. ),
  37. child: ListView.separated(
  38. padding: EdgeInsets.all(0),
  39. itemCount: 3,
  40. itemBuilder: (context,index){
  41. return GestureDetector(
  42. behavior: HitTestBehavior.opaque,
  43. onTap: (){
  44. if(index==0){
  45. showCupertinoModalPopup(
  46. context: context,
  47. builder: (context) {
  48. return CupertinoActionSheet(
  49. actions: <Widget>[
  50. CupertinoActionSheetAction(
  51. child: Text('相机'),
  52. onPressed: () {
  53. Navigator.pop(context);
  54. _picker.getImage(source: ImageSource.camera).then((value){
  55. _uploadImageData(value);
  56. });
  57. },
  58. ),
  59. CupertinoActionSheetAction(
  60. child: Text('相册'),
  61. onPressed: () {
  62. Navigator.pop(context);
  63. _picker.getImage(source: ImageSource.gallery).then((value){
  64. _uploadImageData(value);
  65. });
  66. },
  67. ),
  68. ],
  69. cancelButton: CupertinoActionSheetAction(
  70. child: Text('取消'),
  71. onPressed: () {
  72. Navigator.pop(context);
  73. },
  74. ),
  75. );
  76. }
  77. );
  78. }else{
  79. getStringWidget();
  80. }
  81. },
  82. child: Container(
  83. height: 50,
  84. padding: EdgeInsets.only(left: 18,right: 18),
  85. child: Row(
  86. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  87. children: [
  88. Text(index==0?'用户头像':'用户昵称',style: TextStyle(color: Color(0xFF292929),fontSize: 14,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  89. index==0?Container(
  90. height: 40,
  91. width: 40,
  92. decoration: avatar!=null?BoxDecoration(
  93. borderRadius: BorderRadius.all(Radius.circular(20)),
  94. color: Color(0xFFEFEFEF),
  95. image: DecorationImage(image: NetworkImage(avatar),fit: BoxFit.fill)
  96. ):BoxDecoration(
  97. borderRadius: BorderRadius.all(Radius.circular(20)),
  98. color: Color(0xFFEFEFEF),
  99. ),
  100. ):Text(name!=null?name:'',style: TextStyle(color: Color(0xFFAEB3BD),fontSize: 14),)
  101. ],
  102. ),
  103. ),
  104. );
  105. },
  106. separatorBuilder: (context,index){
  107. return Container(
  108. height: 1.4,
  109. child: Image.asset('lib/images/line.png'),
  110. );
  111. },
  112. physics: NeverScrollableScrollPhysics(),
  113. ),
  114. ),
  115. // GestureDetector(
  116. // onTap: (){
  117. // Navigator.of(context).push(
  118. // CupertinoPageRoute(
  119. // builder: (context){
  120. // return YSMeans(isEdit: true,);
  121. // },settings: const RouteSettings(name: 'YSMeans')
  122. // ),
  123. // );
  124. // },
  125. // child: Container(
  126. // width: MediaQuery.of(context).size.width-10,
  127. // height: 50,
  128. // margin: EdgeInsets.only(top: 5),
  129. // padding: EdgeInsets.only(left: 18,right: 18),
  130. // decoration: BoxDecoration(
  131. // color: Colors.white,
  132. // borderRadius: BorderRadius.all(Radius.circular(6))
  133. // ),
  134. // child: Row(
  135. // mainAxisAlignment: MainAxisAlignment.spaceBetween,
  136. // children: [
  137. // Text('用户资料',style: TextStyle(color: Color(0xFF292929),fontSize: 14,decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  138. // Icon(Icons.chevron_right,size: 20,color: Color(0xFFAEB3BD),)
  139. // ],
  140. // ),
  141. // ),
  142. // ),
  143. ],
  144. ),
  145. ),
  146. );
  147. }
  148. _getInfo() async{
  149. SharedPreferences prefer = await SharedPreferences.getInstance();
  150. setState(() {
  151. avatar = prefer.getString('avatar');
  152. name = prefer.getString('name');
  153. });
  154. }
  155. _uploadImageData(var image) async{
  156. ysUploadFile(context,path: image.path,type: 'avatar',setter: (value) async{
  157. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'user/upAvatar', {'path':value['path']});
  158. if(dict!=null){
  159. SharedPreferences prefer = await SharedPreferences.getInstance();
  160. prefer.setString('avatar', '${value['url']}');
  161. setState(() {
  162. avatar = '${value['url']}';
  163. });
  164. }
  165. });
  166. // var dict = await ysRequestHttpNoLoading(context, requestType.get, 'upQiniuToken', {'type':'avatar'});
  167. // if(dict!=null){
  168. // var result = await syStorage.upload('${image.path}', '${dict['token']}', '${dict['path']}');
  169. // print('$result');
  170. // if(result.success==true){
  171. // SharedPreferences prefer = await SharedPreferences.getInstance();
  172. // prefer.setString('avatar', '${dict['url']}');
  173. // setState(() {
  174. // avatar = '${dict['url']}';
  175. // });
  176. // }
  177. // }
  178. }
  179. getStringWidget(){
  180. TextEditingController textController = TextEditingController(text: name);
  181. showDialog(context: context,builder: (context){
  182. return Dialog(
  183. backgroundColor: Colors.transparent,
  184. child: Container(
  185. width: MediaQuery.of(context).size.width,
  186. padding: EdgeInsets.all(15),
  187. height: 150,
  188. decoration: BoxDecoration(
  189. color: Colors.white,
  190. borderRadius: BorderRadius.all(Radius.circular(10))
  191. ),
  192. child: Column(
  193. crossAxisAlignment: CrossAxisAlignment.start,
  194. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  195. children: [
  196. Text('修改昵称',style: TextStyle(fontSize: 14,color: Color(0xFF292929),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  197. Container(
  198. height: 30,
  199. width: MediaQuery.of(context).size.width-30,
  200. child: CupertinoTextField(
  201. style: TextStyle(fontSize: 13,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  202. placeholderStyle: TextStyle(fontSize: 13,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  203. placeholder: '请输入昵称',
  204. controller: textController,
  205. decoration: BoxDecoration(),
  206. ),
  207. //Text('chooseDate',style: TextStyle(fontSize: 13,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  208. decoration: BoxDecoration(
  209. border: Border(bottom: BorderSide(width: 0.5,color: Color(0xFFD7D7D7)))
  210. ),
  211. ),
  212. Row(
  213. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  214. children: [
  215. Container(),
  216. Row(
  217. children: [
  218. CupertinoButton(
  219. padding: EdgeInsets.all(0),
  220. child: Text('取消',style: TextStyle(fontSize: 13,color: Color(0xFF8E1B3C),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  221. onPressed: (){
  222. Navigator.pop(context);
  223. },
  224. ),
  225. CupertinoButton(
  226. padding: EdgeInsets.all(0),
  227. child: Text('确定',style: TextStyle(fontSize: 13,color: Color(0xFF8E1B3C),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  228. onPressed: () async{
  229. if(textController.text.isEmpty){
  230. return;
  231. }
  232. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'user/upSimpleName', {'simple_name':textController.text});
  233. if(dict!=null){
  234. Navigator.pop(context);
  235. setState(() {
  236. name = textController.value.text;
  237. });
  238. }
  239. },
  240. )
  241. ],
  242. )
  243. ],
  244. )
  245. ],
  246. ),
  247. ),
  248. );
  249. });
  250. }
  251. }