import 'dart:io'; import 'package:city_pickers/city_pickers.dart'; import 'package:city_pickers/modal/result.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:qiniu_flutter_sdk/qiniu_flutter_sdk.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:ysairplane2/base/YSBase.dart'; import 'package:ysairplane2/code/YSCity.dart'; import 'package:ysairplane2/tools/YSNetWorking.dart'; import 'package:ysairplane2/tools/YSTools.dart'; import 'package:image_picker/image_picker.dart'; class YSUserInfo extends StatefulWidget { @override _YSUserInfoState createState() => _YSUserInfoState(); } class _YSUserInfoState extends State {//,{'title':'绑定微信','content':''},{'title':'绑定支付宝','content':''}, ImagePicker _picker = ImagePicker(); //{'title':'公司名称','content':'请输入公司名称'},{'title':'公司职务','content':'请输入职务'}, // {'title':'公司行业','content':'请输入行业'},{'title':'网址','content':'请输入网址'},{'title':'所在地区','content':'请选择公司所在地区'} List array = [{'title':'头像','content':''},{'title':'真实姓名','content':'请输入真实姓名'},{'title':'性别','content':'请选择性别'}, {'title':'地区','content':'请选择地区'},{'title':'登录手机','content':''}, {'title':'邮箱地址','content':'请输入邮箱地址'}]; List chooses = ['男','女']; String _tokenStr = ''; String _urlStr = ''; String _phone = ''; String _name = ''; String _email = ''; String _city = ''; String _avatar = ''; TextEditingController _field = TextEditingController(); @override void initState() { Future.delayed(Duration(seconds: 0)).then((value){ _getUserInfoData(); _getQiNiuTokenData(); }); super.initState(); } @override void dispose() { _field.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return YSBase( ystitle: '个人资料', yschild: Container( height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44, width: MediaQuery.of(context).size.width, color: Color(0xFFF5F6F8), child: ListView.separated( itemBuilder: (context,index){ return GestureDetector( onTap: () async{ if(index==0){ showCupertinoModalPopup( context: context, builder: (context) { return CupertinoActionSheet( actions: [ CupertinoActionSheetAction( child: Text('拍摄照片'), onPressed: () { Navigator.pop(context); _picker.getImage(source: ImageSource.camera,imageQuality: 50).then((value){ _onUpload(value); }); }, ), CupertinoActionSheetAction( child: Text('选择图片'), onPressed: () { Navigator.pop(context); _picker.getImage(source: ImageSource.gallery,imageQuality: 50).then((value){ _onUpload(value); }); }, ), ], cancelButton: CupertinoActionSheetAction( child: Text('取消'), onPressed: () { Navigator.pop(context); }, ), ); } ); }else if(index==6||index==7||index==3||index==12){ if(index==3||index==12){ FocusScope.of(context).unfocus(); Result result = await CityPickers.showCityPicker( context: context, ); print(result); if(result!=null){ _city = result.provinceName+' '+result.cityName+' '+result.areaName; _postEditUserData({'region':_city}); } }else{ } }else if(index==1||index==5||index==8||index==9||index==10||index==11){ _field.text = ''; if(index==1){ _field.text = _name; }else if(index==5){ _field.text = _email; } showModalBottomSheet( isScrollControlled: true, barrierColor: Colors.black26, backgroundColor: Colors.transparent, context: context, builder: (context){ return SingleChildScrollView( padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), child: Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(10)) ), child: Column( children: [ Container( padding: EdgeInsets.only(top: 10,bottom: 10,left: 10,right: 10), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(index==1?'真实姓名':index==5?'邮箱地址':index==8?'公司名称':index==9?'公司职务':index==10?'公司行业':'网址', style: TextStyle(fontSize: 14,color: Color(0xFF000000),decoration: TextDecoration.none,fontWeight: FontWeight.bold),), GestureDetector( onTap: (){Navigator.pop(context);}, child: Icon(Icons.close,size: 20,color: Color(0xFF9A9A9A),), ) ], ), ), Container( height: 50, width: MediaQuery.of(context).size.width-30, child: CupertinoTextField( placeholder: '请输入', style: TextStyle(fontSize: 15,color: Color(0xFF9A9A9A),decoration: TextDecoration.none,fontWeight: FontWeight.normal,), placeholderStyle: TextStyle(fontSize: 15,color: Color(0xFF9A9A9A),decoration: TextDecoration.none,fontWeight: FontWeight.normal), autofocus: true, decoration: BoxDecoration(), maxLines: 10, controller: _field, keyboardType: index==5?TextInputType.emailAddress:TextInputType.text, ), decoration: BoxDecoration( border: Border(bottom: BorderSide(color: Color(0xFFF5F6F8),width: 0.5)) ), margin: EdgeInsets.only(top: 10), ), GestureDetector( onTap: (){ if(_field.text.isEmpty)return; Navigator.pop(context); if(index==1){ _postEditUserData({'nickname':_field.text}); _name = _field.text; }else if(index==5){ if(isEmail(_field.text)==false){ ysFlutterToast(context, '邮箱格式错误'); return; } _postEditUserData({'mail':_field.text}); _email = _field.text; } }, child: Container( margin: EdgeInsets.all(15), height: 40, width: MediaQuery.of(context).size.width-40, alignment: Alignment.center, decoration: BoxDecoration( color: Color(0xFF007AFF), borderRadius: BorderRadius.all(Radius.circular(6)) ), child: Text('完成',style: TextStyle(fontSize: 17,color: Colors.white,fontWeight: FontWeight.bold,decoration: TextDecoration.none),), ), ) ], ), ), ); } ); }else{ } }, child: Container( height: 50, color: Colors.white, padding: EdgeInsets.only(left: 15,right: 15), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text('${array[index]['title']}',style: TextStyle(fontSize: 16,color: Color(0xFF000000)),), index==0?Container( height: 40, width: 40, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(20)), color: Colors.black12 ), child: _avatar.isNotEmpty?ClipRRect( borderRadius: BorderRadius.all(Radius.circular(20)), child: ysImageLoad( imageUrl: _avatar, fit: BoxFit.fill, height: 40, width: 40, ), ):Container(), ):index==6||index==7||index==3||index==12?Row( children: [ Text(index==3&&_city.isNotEmpty?_city:'${array[index]['content']}',style: TextStyle(fontSize: 16,color: Color(0xFF9A9A9A)),), Icon(Icons.keyboard_arrow_right,size: 20,color: Color(0xFF9A9A9A),) ], ):index==1||index==4||index==5||index==8||index==9||index==10||index==11?Text( index==1&&_name.isNotEmpty?_name:index==5&&_email.isNotEmpty?_email: index==4&&_phone.isNotEmpty?_phone:'${array[index]['content']}', style: TextStyle(fontSize: 16,color: Color(0xFF9A9A9A)), ):DropdownButton( value: '${chooses[0]}', items: [ for(int i=0;i