YSCommnetAdd.dart 11 KB

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