YSCommnetAdd.dart 12 KB

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