123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- import 'package:cached_network_image/cached_network_image.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:sy_flutter_qiniu_storage/sy_flutter_qiniu_storage.dart';
- import 'package:ysairplane/base/YSBase.dart';
- import 'package:ysairplane/code/YSCity.dart';
- import 'package:ysairplane/tools/YSNetWorking.dart';
- import 'package:ysairplane/tools/YSTools.dart';
- import 'package:image_picker/image_picker.dart';
- class YSUserInfo extends StatefulWidget {
- @override
- _YSUserInfoState createState() => _YSUserInfoState();
- }
- class _YSUserInfoState extends State<YSUserInfo> {
- ImagePicker _picker = ImagePicker();
- List array = [{'title':'头像','content':''},{'title':'真实姓名','content':'请输入真实姓名'},{'title':'性别','content':'请选择性别'},
- {'title':'地区','content':'请选择地区'},{'title':'登录手机','content':''},
- {'title':'邮箱地址','content':'请输入邮箱地址'},{'title':'绑定微信','content':''},{'title':'绑定支付宝','content':''},
- {'title':'公司名称','content':'请输入公司名称'},{'title':'公司职务','content':'请输入职务'},
- {'title':'公司行业','content':'请输入行业'},{'title':'网址','content':'请输入网址'},{'title':'所在地区','content':'请选择公司所在地区'}];
- List chooses = ['男','女'];
- String _phone = '';
- String _avatar;
- String _tokenStr = '';
- String _urlStr = '';
- @override
- void initState() {
- Future.delayed(Duration(seconds: 0)).then((value){
- _getQiNiuTokenData();
- });
- super.initState();
- }
- @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: (){
- 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){
- Navigator.of(context).push(
- CupertinoPageRoute(builder: (context){
- return YSCity();
- })
- ).then((value){
- if(value!=null){
- }
- });
- }else{
- }
- }else if(index==1||index==5||index==8||index==9||index==10||index==11){
- Navigator.push(context, PopRoute(child: BottomInputDialog(
- height: 185,
- color: Colors.white,
- inputView: Column(
- children: [
- Container(
- padding: EdgeInsets.only(top: 5,bottom: 10,left: 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),),
- 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,
- ),
- decoration: BoxDecoration(
- border: Border(bottom: BorderSide(color: Color(0xFFF5F6F8),width: 0.5))
- ),
- margin: EdgeInsets.only(top: 10),
- ),
- 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!=null?ClipRRect(
- borderRadius: BorderRadius.all(Radius.circular(20)),
- child: CachedNetworkImage(
- imageUrl: _avatar,
- fit: BoxFit.fill,
- ),
- ):Container(),
- ):index==6||index==7||index==3||index==12?Row(
- children: [
- Text('${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==4?_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);
- 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){
- _phone = prefer.getString('phone');
- _avatar = prefer.getString('avatar');
- _tokenStr = dict['token'];
- _urlStr = dict['prefix'];
- setState(() {
- });
- }
- }
- }
|