123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- 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<YSUserInfo> {//,{'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: <Widget>[
- 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<chooses.length;i++)DropdownMenuItem(child: Text('${chooses[i]}'),value: '${chooses[i]}',),
- ],
- onChanged: (value){
- },
- underline: Container(),
- icon: Icon(Icons.keyboard_arrow_down,size: 20,color: Color(0xFF999999),),
- style: TextStyle(fontSize: 15,color: Color(0xFF999999)),
- )
- ],
- ),
- ),
- );
- },
- separatorBuilder: (context,index){
- return Container(
- color: Color(0xFFF5F6F8),
- height: index==3||index==7?10:0.5,
- );
- },
- itemCount: array.length,
- padding: EdgeInsets.only(top: 10,bottom: 30),
- ),
- ),
- );
- }
- _postEditUserData(var request) async{
- Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/applets/center/info/update',parameter: request,isLoading: false,
- isToken: true,refresh: (){_postEditUserData(request);});
- if(dict!=null){
- setState(() {});
- }
- }
- _onUpload(var value) async {
- if (value == null) {
- return;
- }
- print(value.path);
- print(_tokenStr);
- Storage storage = Storage();
- storage.putFile(
- File(value.path),
- _tokenStr,
- options: PutOptions(
- key: DateTime.now().millisecondsSinceEpoch.toString() +'.' +value.path.split('.').last,
- ),
- ).then((result) async{
- _postEditUserData({'avatar':_urlStr+'${result.key}'});
- });
- // final syStorage = new SyFlutterQiniuStorage();
- // //监听上传进度
- // syStorage.onChanged().listen((dynamic percent) {
- // print(percent);
- // });
- // //上传文件
- // var result = await syStorage.upload(value.path, _tokenStr, DateTime.now().millisecondsSinceEpoch.toString() +'.' +value.path.split('.').last);
- // if(result.success==true){
- // _postEditUserData({'avatar':_urlStr+'${result.result['key']}'});
- // }
- // print(result);
- }
- _getQiNiuTokenData() async{
- SharedPreferences prefer = await SharedPreferences.getInstance();
- Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/getToken',parameter: {},isLoading: false,isToken: false);
- if(dict!=null){
- _avatar = prefer.getString('avatar');
- _tokenStr = dict['token'];
- _urlStr = dict['prefix'];
- setState(() {
- });
- }
- }
- _getUserInfoData() async{
- Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/center/info',parameter: {},isLoading: false,isToken: true);
- if(dict!=null){
- _phone = dict['data']['phoneNumber'];
- _name = dict['data']['nickname'];
- _email = dict['data']['mail']??'';
- }
- }
- }
|