YSCommnetAdd.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:qiniu_flutter_sdk/qiniu_flutter_sdk.dart';
  5. import 'package:ysairplane2/base/YSBase.dart';
  6. import 'package:ysairplane2/tools/YSNetWorking.dart';
  7. import 'package:ysairplane2/tools/YSTools.dart';
  8. import 'package:image_picker/image_picker.dart';
  9. import 'package:smooth_star_rating/smooth_star_rating.dart';
  10. class YSCommentAdd extends StatefulWidget {
  11. final String orderStr;
  12. const YSCommentAdd({Key key, this.orderStr}) : super(key: key);
  13. @override
  14. _YSCommentAddState createState() => _YSCommentAddState();
  15. }
  16. class _YSCommentAddState extends State<YSCommentAdd> {
  17. ImagePicker _picker = ImagePicker();
  18. List _images = [];
  19. List _types = [];
  20. List _comments = [];
  21. String _tokenStr = '';
  22. String _urlStr = '';
  23. TextEditingController _content = TextEditingController();
  24. @override
  25. void initState() {
  26. Future.delayed(Duration(seconds: 0)).then((value){
  27. _getQiNiuTokenData();
  28. _getCommentType();
  29. });
  30. super.initState();
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. return YSBase(
  35. ystitle: '点评',
  36. yschild: Container(
  37. height: MediaQuery.of(context).size.height-MediaQuery.of(context).padding.top-44,
  38. width: MediaQuery.of(context).size.width,
  39. color: Color(0xFFF4F5F6),
  40. child: Column(
  41. children: [
  42. Container(
  43. margin: EdgeInsets.only(top: hsp(20)),
  44. padding: EdgeInsets.all(hsp(30)),
  45. color: Colors.white,
  46. child: ListView.builder(
  47. itemBuilder: (context,index){
  48. return Container(
  49. height: hsp(80),
  50. child: Row(
  51. children: [
  52. Text('${_types[index]['name']}',style: TextStyle(fontSize: zsp(30),color: Color(0xFF535353)),),
  53. Container(
  54. margin: EdgeInsets.only(left: wsp(80),right: wsp(80)),
  55. child: SmoothStarRating(
  56. rating: double.parse('${_comments[index]['score']}'),
  57. isReadOnly: false,
  58. size: hsp(40),
  59. filledIconData: Icons.star,
  60. halfFilledIconData: Icons.star_half,
  61. defaultIconData: Icons.star_border,
  62. starCount: int.parse('${_types[index]['totalScore']}'),
  63. allowHalfRating: true,
  64. spacing: 1.0,
  65. onRated: (value) {
  66. _comments[index]['score'] = value;
  67. },
  68. color: Color(0xFFF97C00),
  69. borderColor: Color(0xFFF97C00),
  70. ),
  71. ),
  72. //Text('超棒',style: TextStyle(fontSize: zsp(30),color: Color(0xFFBFBFBF)),),
  73. ],
  74. ),
  75. );
  76. },
  77. itemCount: _types.length,
  78. padding: EdgeInsets.all(0),
  79. shrinkWrap: true,
  80. physics: NeverScrollableScrollPhysics(),
  81. ),
  82. ),
  83. Container(
  84. margin: EdgeInsets.only(top: hsp(10)),
  85. padding: EdgeInsets.all(hsp(30)),
  86. width: MediaQuery.of(context).size.width,
  87. height: hsp(180),
  88. color: Colors.white,
  89. child: ListView.separated(
  90. scrollDirection: Axis.horizontal,
  91. itemBuilder: (context,index){
  92. return GestureDetector(
  93. onTap: (){
  94. showCupertinoModalPopup(
  95. context: context,
  96. builder: (context) {
  97. return CupertinoActionSheet(
  98. actions: <Widget>[
  99. CupertinoActionSheetAction(
  100. child: Text('拍摄照片'),
  101. onPressed: () {
  102. Navigator.pop(context);
  103. _picker.getImage(source: ImageSource.camera).then((value){
  104. _onUpload(value);
  105. });
  106. },
  107. ),
  108. CupertinoActionSheetAction(
  109. child: Text('选择图片'),
  110. onPressed: () {
  111. Navigator.pop(context);
  112. _picker.getImage(source: ImageSource.gallery).then((value){
  113. _onUpload(value);
  114. });
  115. },
  116. ),
  117. ],
  118. cancelButton: CupertinoActionSheetAction(
  119. child: Text('取消'),
  120. onPressed: () {
  121. Navigator.pop(context);
  122. },
  123. ),
  124. );
  125. }
  126. );
  127. },
  128. child: index==_images.length?Container(
  129. height: hsp(120),
  130. width: hsp(120),
  131. decoration: BoxDecoration(
  132. color: Color(0xFFF2F2F2),
  133. borderRadius: BorderRadius.all(Radius.circular(10))
  134. ),
  135. child: Icon(Icons.add,size: 25,color: Color(0xFF9A9A9A),),
  136. ):Container(
  137. height: hsp(120),
  138. width: hsp(120),
  139. decoration: BoxDecoration(
  140. borderRadius: BorderRadius.all(Radius.circular(10)),
  141. image: DecorationImage(image: NetworkImage(_images[index]),fit: BoxFit.fill)
  142. ),
  143. )
  144. );
  145. },
  146. separatorBuilder: (context,index){
  147. return Container(width: 10,);
  148. },
  149. itemCount: _images.length+1,
  150. padding: EdgeInsets.all(0),
  151. shrinkWrap: true,
  152. ),
  153. ),
  154. Container(
  155. margin: EdgeInsets.only(top: hsp(10)),
  156. padding: EdgeInsets.all(hsp(30)),
  157. width: MediaQuery.of(context).size.width,
  158. color: Colors.white,
  159. child: Column(
  160. children: [
  161. GestureDetector(
  162. onTap: (){
  163. Navigator.push(context, PopRoute(child: BottomInputDialog(
  164. height: 50,
  165. inputView: Row(
  166. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  167. children: [
  168. Container(
  169. width: MediaQuery.of(context).size.width-100,
  170. child: CupertinoTextField(
  171. placeholder: '说点儿好听的~',
  172. style: TextStyle(fontSize: 15,color: Color(0xFF5A5A5A),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  173. placeholderStyle: TextStyle(fontSize: 15,color: Color(0xFF5A5A5A),decoration: TextDecoration.none,fontWeight: FontWeight.normal),
  174. autofocus: true,
  175. decoration: BoxDecoration(),
  176. controller: _content,
  177. ),
  178. ),
  179. Icon(Icons.alternate_email,size: 25,color: Color(0xFFA1A1A2),),
  180. Icon(Icons.tag_faces,size: 25,color: Color(0xFFA1A1A2),),
  181. ],
  182. ),
  183. )));
  184. },
  185. child: Container(
  186. height: hsp(200),
  187. decoration: BoxDecoration(
  188. color: Color(0xFFF4F5F6),
  189. borderRadius: BorderRadius.all(Radius.circular(5))
  190. ),
  191. width: MediaQuery.of(context).size.width-hsp(60),
  192. padding: EdgeInsets.all(hsp(20)),
  193. child: SingleChildScrollView(
  194. child: Text(_content.text.isEmpty?'添加正文':_content.text,style: TextStyle(fontSize: 15,color: Color(0xFF9A9A9A)),),
  195. ),
  196. ),
  197. ),
  198. Container(
  199. width: MediaQuery.of(context).size.width-hsp(60),
  200. child: RichText(
  201. text: TextSpan(
  202. text: '还差',
  203. style: TextStyle(fontSize: 14,color: Color(0xFF9A9A9A)),
  204. children: [
  205. TextSpan(
  206. text: '15',
  207. style: TextStyle(color: Color(0xFFEB8232))
  208. ),
  209. TextSpan(
  210. text: '字,即可发表点评'
  211. )
  212. ]
  213. ),
  214. ),
  215. height: hsp(60),
  216. alignment: Alignment.centerRight,
  217. ),
  218. ],
  219. ),
  220. ),
  221. GestureDetector(
  222. onTap: (){
  223. _postCommentData();
  224. },
  225. child: Container(
  226. margin: EdgeInsets.only(top: hsp(200)),
  227. width: MediaQuery.of(context).size.width-hsp(100),
  228. height: hsp(92),
  229. alignment: Alignment.center,
  230. decoration: BoxDecoration(
  231. color: Color(0xFF143C64),
  232. borderRadius: BorderRadius.all(Radius.circular(5))
  233. ),
  234. child: Text('发布',style: TextStyle(fontSize: 18,color: Colors.white,fontWeight: FontWeight.bold),),
  235. ),
  236. )
  237. ],
  238. ),
  239. ),
  240. );
  241. }
  242. _getQiNiuTokenData() async{
  243. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/getToken',parameter: {},isLoading: false,isToken: false);
  244. if(dict!=null){
  245. _tokenStr = dict['token'];
  246. _urlStr = dict['prefix'];
  247. }
  248. }
  249. _onUpload(var value) async {
  250. if (value == null) {
  251. return;
  252. }
  253. print(value.path);
  254. print(_tokenStr);
  255. Storage storage = Storage();
  256. storage.putFile(
  257. File(value.path),
  258. _tokenStr,
  259. options: PutOptions(
  260. key: DateTime.now().millisecondsSinceEpoch.toString() +'.' +value.path.split('.').last,
  261. ),
  262. ).then((result) async{
  263. setState(() {
  264. _images.add(_urlStr+'${result.key}');
  265. });
  266. });
  267. // final syStorage = new SyFlutterQiniuStorage();
  268. // //监听上传进度
  269. // syStorage.onChanged().listen((dynamic percent) {
  270. // print(percent);
  271. // });
  272. // //上传文件
  273. // var result = await syStorage.upload(value.path, _tokenStr, DateTime.now().millisecondsSinceEpoch.toString() +'.' +value.path.split('.').last);
  274. // if(result.success==true){
  275. // setState(() {
  276. // _images.add(_urlStr+'${result.result['key']}');
  277. // });
  278. // }
  279. // print(result);
  280. }
  281. _getCommentType() async{
  282. Map dict = await ysRequestHttp(context,type: requestType.get,api: '/app/applets/orderscoring/type/list',parameter: {},isLoading: false,isToken: false);
  283. if(dict!=null){
  284. _types = dict['data'];
  285. _types.forEach((element) {
  286. _comments.add({'orderscoringtypeid':element['id'],'score':5});
  287. });
  288. setState(() {});
  289. }
  290. }
  291. _postCommentData() async{
  292. if(_content.text.isEmpty){
  293. ysFlutterToast(context, '请输入评价内容');
  294. return;
  295. }
  296. Map request = {};
  297. request['content'] = _content.text;
  298. request['ordersn'] = widget.orderStr;
  299. request['picture'] = _images.join(',');
  300. request['dtOrderScoringList'] = _comments;
  301. Map dict = await ysRequestHttp(context,type: requestType.post,api: '/app/applets/orderscoring/add',parameter: request,
  302. isLoading: false,isToken: true);
  303. if(dict!=null){
  304. Navigator.of(context).pop('');
  305. }
  306. }
  307. }