import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:qiniu_flutter_sdk/qiniu_flutter_sdk.dart'; import 'package:ysairplane2/base/YSBase.dart'; import 'package:ysairplane2/tools/YSNetWorking.dart'; import 'package:ysairplane2/tools/YSTools.dart'; import 'package:image_picker/image_picker.dart'; import 'package:smooth_star_rating/smooth_star_rating.dart'; class YSCommentAdd extends StatefulWidget { final String orderStr; const YSCommentAdd({Key key, this.orderStr}) : super(key: key); @override _YSCommentAddState createState() => _YSCommentAddState(); } class _YSCommentAddState extends State { ImagePicker _picker = ImagePicker(); List _images = []; List _types = []; List _comments = []; String _tokenStr = ''; String _urlStr = ''; TextEditingController _content = TextEditingController(); @override void initState() { Future.delayed(Duration(seconds: 0)).then((value){ _getQiNiuTokenData(); _getCommentType(); }); 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(0xFFF4F5F6), child: Column( children: [ Container( margin: EdgeInsets.only(top: hsp(20)), padding: EdgeInsets.all(hsp(30)), color: Colors.white, child: ListView.builder( itemBuilder: (context,index){ return Container( height: hsp(80), child: Row( children: [ Text('${_types[index]['name']}',style: TextStyle(fontSize: zsp(30),color: Color(0xFF535353)),), Container( margin: EdgeInsets.only(left: wsp(80),right: wsp(80)), child: SmoothStarRating( rating: double.parse('${_comments[index]['score']}'), isReadOnly: false, size: hsp(40), filledIconData: Icons.star, halfFilledIconData: Icons.star_half, defaultIconData: Icons.star_border, starCount: int.parse('${_types[index]['totalScore']}'), allowHalfRating: true, spacing: 1.0, onRated: (value) { _comments[index]['score'] = value; }, color: Color(0xFFF97C00), borderColor: Color(0xFFF97C00), ), ), //Text('超棒',style: TextStyle(fontSize: zsp(30),color: Color(0xFFBFBFBF)),), ], ), ); }, itemCount: _types.length, padding: EdgeInsets.all(0), shrinkWrap: true, physics: NeverScrollableScrollPhysics(), ), ), Container( margin: EdgeInsets.only(top: hsp(10)), padding: EdgeInsets.all(hsp(30)), width: MediaQuery.of(context).size.width, height: hsp(180), color: Colors.white, child: ListView.separated( scrollDirection: Axis.horizontal, itemBuilder: (context,index){ return GestureDetector( onTap: (){ showCupertinoModalPopup( context: context, builder: (context) { return CupertinoActionSheet( actions: [ CupertinoActionSheetAction( child: Text('拍摄照片'), onPressed: () { Navigator.pop(context); _picker.getImage(source: ImageSource.camera).then((value){ _onUpload(value); }); }, ), CupertinoActionSheetAction( child: Text('选择图片'), onPressed: () { Navigator.pop(context); _picker.getImage(source: ImageSource.gallery).then((value){ _onUpload(value); }); }, ), ], cancelButton: CupertinoActionSheetAction( child: Text('取消'), onPressed: () { Navigator.pop(context); }, ), ); } ); }, child: index==_images.length?Container( height: hsp(120), width: hsp(120), decoration: BoxDecoration( color: Color(0xFFF2F2F2), borderRadius: BorderRadius.all(Radius.circular(10)) ), child: Icon(Icons.add,size: 25,color: Color(0xFF9A9A9A),), ):Container( height: hsp(120), width: hsp(120), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(10)), image: DecorationImage(image: NetworkImage(_images[index]),fit: BoxFit.fill) ), ) ); }, separatorBuilder: (context,index){ return Container(width: 10,); }, itemCount: _images.length+1, padding: EdgeInsets.all(0), shrinkWrap: true, ), ), Container( margin: EdgeInsets.only(top: hsp(10)), padding: EdgeInsets.all(hsp(30)), width: MediaQuery.of(context).size.width, color: Colors.white, child: Column( children: [ GestureDetector( onTap: (){ Navigator.push(context, PopRoute(child: BottomInputDialog( height: 50, inputView: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( width: MediaQuery.of(context).size.width-100, child: CupertinoTextField( placeholder: '说点儿好听的~', style: TextStyle(fontSize: 15,color: Color(0xFF5A5A5A),decoration: TextDecoration.none,fontWeight: FontWeight.normal), placeholderStyle: TextStyle(fontSize: 15,color: Color(0xFF5A5A5A),decoration: TextDecoration.none,fontWeight: FontWeight.normal), autofocus: true, decoration: BoxDecoration(), controller: _content, ), ), Icon(Icons.alternate_email,size: 25,color: Color(0xFFA1A1A2),), Icon(Icons.tag_faces,size: 25,color: Color(0xFFA1A1A2),), ], ), ))); }, child: Container( height: hsp(200), decoration: BoxDecoration( color: Color(0xFFF4F5F6), borderRadius: BorderRadius.all(Radius.circular(5)) ), width: MediaQuery.of(context).size.width-hsp(60), padding: EdgeInsets.all(hsp(20)), child: SingleChildScrollView( child: Text(_content.text.isEmpty?'添加正文':_content.text,style: TextStyle(fontSize: 15,color: Color(0xFF9A9A9A)),), ), ), ), Container( width: MediaQuery.of(context).size.width-hsp(60), child: RichText( text: TextSpan( text: '还差', style: TextStyle(fontSize: 14,color: Color(0xFF9A9A9A)), children: [ TextSpan( text: '15', style: TextStyle(color: Color(0xFFEB8232)) ), TextSpan( text: '字,即可发表点评' ) ] ), ), height: hsp(60), alignment: Alignment.centerRight, ), ], ), ), GestureDetector( onTap: (){ _postCommentData(); }, child: Container( margin: EdgeInsets.only(top: hsp(200)), width: MediaQuery.of(context).size.width-hsp(100), height: hsp(92), alignment: Alignment.center, decoration: BoxDecoration( color: Color(0xFF143C64), borderRadius: BorderRadius.all(Radius.circular(5)) ), child: Text('发布',style: TextStyle(fontSize: 18,color: Colors.white,fontWeight: FontWeight.bold),), ), ) ], ), ), ); } _getQiNiuTokenData() async{ Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/getToken',parameter: {},isLoading: false,isToken: false); if(dict!=null){ _tokenStr = dict['token']; _urlStr = dict['prefix']; } } _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{ setState(() { _images.add(_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){ // setState(() { // _images.add(_urlStr+'${result.result['key']}'); // }); // } // print(result); } _getCommentType() async{ Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/orderscoring/type/list',parameter: {},isLoading: false,isToken: false); if(dict!=null){ _types = dict['data']; _types.forEach((element) { _comments.add({'orderscoringtypeid':element['id'],'score':5}); }); setState(() {}); } } _postCommentData() async{ if(_content.text.isEmpty){ ysFlutterToast(context, '请输入评价内容'); return; } Map request = {}; request['content'] = _content.text; request['ordersn'] = widget.orderStr; request['picture'] = _images.join(','); request['dtOrderScoringList'] = _comments; Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/applets/orderscoring/add',parameter: request, isLoading: false,isToken: true); if(dict!=null){ Navigator.of(context).pop(''); } } }