YSFeedback.dart 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  4. import 'package:image_picker/image_picker.dart';
  5. import 'base/YSBase.dart';
  6. import 'base/YSTools.dart';
  7. class YSFeedback extends StatefulWidget {
  8. @override
  9. _YSFeedbackState createState() => _YSFeedbackState();
  10. }
  11. class _YSFeedbackState extends State<YSFeedback> {
  12. TextEditingController _content = TextEditingController();
  13. TextEditingController _phone = TextEditingController();
  14. List urls = [];
  15. List paths = [];
  16. final ImagePicker _picker = ImagePicker();
  17. @override
  18. Widget build(BuildContext context) {
  19. return YSBase(
  20. ystitle: '意见反馈',
  21. yschild: Container(
  22. decoration: BoxDecoration(
  23. color: Colors.white,
  24. borderRadius: BorderRadius.only(topLeft: Radius.circular(20),topRight: Radius.circular(20))
  25. ),
  26. child: SingleChildScrollView(
  27. padding: EdgeInsets.all(20),
  28. child: Column(
  29. crossAxisAlignment: CrossAxisAlignment.start,
  30. children: [
  31. Text('详情',style: TextStyle(fontSize: 14,color: Color(0xFF292929)),),
  32. Container(
  33. height: 150,
  34. child: CupertinoTextField(
  35. placeholder: '请输入问题描述(10~500 个字内)',
  36. maxLength: 500,
  37. style: TextStyle(fontSize: 14,color: Color(0xFF292929)),
  38. placeholderStyle: TextStyle(fontSize: 14,color: Color(0xFF808080)),
  39. maxLines: 30,
  40. decoration: BoxDecoration(),
  41. controller: _content,
  42. ),
  43. ),
  44. Container(
  45. margin: EdgeInsets.only(top: 10),
  46. width: MediaQuery.of(context).size.width,
  47. height: 1.5,
  48. child: Image.asset('lib/images/line.png'),
  49. ),
  50. Container(
  51. height: 50,
  52. child: Row(
  53. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  54. children: [
  55. Text('联系方式',style: TextStyle(fontSize: 14,color: Color(0xFF292929)),),
  56. Container(
  57. width: MediaQuery.of(context).size.width-100,
  58. child: CupertinoTextField(
  59. placeholder: '请输入',
  60. style: TextStyle(fontSize: 14,color: Color(0xFF292929)),
  61. placeholderStyle: TextStyle(fontSize: 14,color: Color(0xFF808080)),
  62. decoration: BoxDecoration(),
  63. textAlign: TextAlign.end,
  64. controller: _phone,
  65. keyboardType: TextInputType.phone,
  66. ),
  67. ),
  68. ],
  69. ),
  70. ),
  71. Container(
  72. margin: EdgeInsets.only(bottom: 15),
  73. width: MediaQuery.of(context).size.width,
  74. height: 1.5,
  75. child: Image.asset('lib/images/line.png'),
  76. ),
  77. Text('图片',style: TextStyle(fontSize: 14,color: Color(0xFF292929)),),
  78. Container(
  79. margin: EdgeInsets.only(top: 10,bottom: 100),
  80. height: (MediaQuery.of(context).size.width-60)/5,
  81. width: MediaQuery.of(context).size.width-40,
  82. child: ListView.separated(
  83. itemBuilder: (context,index){
  84. return GestureDetector(
  85. onTap: (){
  86. if(index<urls.length){
  87. }else{
  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,imageQuality: 50).then((value) => {
  98. _uploadImageData(value)
  99. });
  100. },
  101. ),
  102. CupertinoActionSheetAction(
  103. child: Text('相册'),
  104. onPressed: () {
  105. Navigator.pop(context);
  106. _picker.getImage(source: ImageSource.gallery,imageQuality: 50).then((value) => {
  107. _uploadImageData(value)
  108. });
  109. },
  110. ),
  111. ],
  112. cancelButton: CupertinoActionSheetAction(
  113. child: Text('取消'),
  114. onPressed: () {
  115. Navigator.pop(context);
  116. },
  117. ),
  118. );
  119. }
  120. );
  121. }
  122. },
  123. child: index==urls.length?Container(
  124. height: (MediaQuery.of(context).size.width-60)/5,
  125. width: (MediaQuery.of(context).size.width-60)/5,
  126. decoration: BoxDecoration(
  127. color: Color(0xFFEFEFEF),
  128. borderRadius: BorderRadius.all(Radius.circular(3))
  129. ),
  130. child: Icon(Icons.add,size: 20,color: Color(0xFFB3B3B3),),
  131. ):Container(
  132. height: (MediaQuery.of(context).size.width-60)/5,
  133. width: (MediaQuery.of(context).size.width-60)/5,
  134. decoration: BoxDecoration(
  135. color: Color(0xFFEFEFEF),
  136. borderRadius: BorderRadius.all(Radius.circular(3)),
  137. image: DecorationImage(image: NetworkImage('${urls[index]}'),fit: BoxFit.fill,)
  138. ),
  139. ),
  140. );
  141. },
  142. separatorBuilder: (context,index){
  143. return Container(height: 70,width: 5,color: Colors.white,);
  144. },
  145. itemCount: urls.length+1,
  146. scrollDirection: Axis.horizontal,
  147. ),
  148. ),
  149. CupertinoButton(
  150. padding: EdgeInsets.all(0),
  151. child: Container(
  152. margin: EdgeInsets.only(left: 55),
  153. width: MediaQuery.of(context).size.width-150,
  154. height: 40,
  155. decoration: BoxDecoration(
  156. color: Color(0xFFEA6C8F),
  157. borderRadius: BorderRadius.all(Radius.circular(20))
  158. ),
  159. alignment: Alignment.center,
  160. child: Text('提交',style: TextStyle(fontSize: 16,color: Colors.white,decoration: TextDecoration.none),),
  161. ),
  162. onPressed: (){
  163. _postFeedbackData();
  164. },
  165. )
  166. ],
  167. ),
  168. ),
  169. ),
  170. );
  171. }
  172. _uploadImageData(var image) async{
  173. ysUploadFile(context,path: image.path,type: 'advice',setter: (value){
  174. paths.add('${value['path']}');
  175. urls.add('${value['url']}');
  176. setState(() {});
  177. });
  178. // var dict = await ysRequestHttpNoLoading(context, requestType.get, 'upQiniuToken', {'type':'advice'});
  179. // if(dict!=null){
  180. // var result = await syStorage.upload('${image.path}', '${dict['token']}', '${dict['path']}');
  181. // if(result.success==true){
  182. // paths.add('${dict['path']}');
  183. // setState(() {
  184. // urls.add('${dict['url']}');
  185. // });
  186. // }
  187. // }
  188. }
  189. _postFeedbackData() async{
  190. if(_content.text==null || _content.text.isEmpty){
  191. ysFlutterToast(context, '请输入反馈内容');
  192. return;
  193. }
  194. if(_content.text.length<10){
  195. ysFlutterToast(context, '反馈内容不能少于10个字');
  196. return;
  197. }
  198. Map request = Map();
  199. request['body'] = _content.text;
  200. request['contact'] = _phone.text;
  201. request['covers'] = paths;
  202. Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'i/advice', request);
  203. if(dict!=null){
  204. Navigator.pop(context);
  205. }
  206. }
  207. }