YSMineQuestionnaireDetail.dart 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import 'package:flutter/material.dart';
  2. import '../base/YSBase.dart';
  3. import '../base/YSNetWorking.dart';
  4. class YSMineQuestionnaireDetail extends StatefulWidget {
  5. final questionId;
  6. const YSMineQuestionnaireDetail({Key key, this.questionId}) : super(key: key);
  7. @override
  8. _YSMineQuestionnaireDetailState createState() => _YSMineQuestionnaireDetailState();
  9. }
  10. class _YSMineQuestionnaireDetailState extends State<YSMineQuestionnaireDetail> {
  11. bool _isEnable = false;
  12. List _dataArray = [];
  13. MaterialColor _selectedColor = Colors.blue;
  14. @override
  15. void initState() {
  16. Future.delayed(Duration(seconds: 0)).then((value) {
  17. _getQuestionData();
  18. });
  19. super.initState();
  20. }
  21. @override
  22. Widget build(BuildContext context) {
  23. return YSBase(
  24. ystitle: '调查问卷详情',
  25. yschild: Stack(
  26. children: [
  27. Container(
  28. height: MediaQuery.of(context).size.height,
  29. width: MediaQuery.of(context).size.width,
  30. child: ListView.separated(
  31. itemBuilder: (context,index){
  32. Map item = _dataArray[index];
  33. List array = item['options'];
  34. return Container(
  35. padding: EdgeInsets.all(15),
  36. child: LayoutBuilder(
  37. builder: (context,conSize){
  38. return Column(
  39. crossAxisAlignment: CrossAxisAlignment.start,
  40. children: [
  41. Text('$index.${item['title']}',style: TextStyle(fontSize: 16,color: Color(0xFF606266)),),
  42. Container(
  43. padding: EdgeInsets.only(top: 10,bottom: 10),
  44. child: Text(item['description'],style: TextStyle(fontSize: 12,color: Color(0xFF989898)),),
  45. ),
  46. ListView.separated(
  47. itemBuilder: (context,index){
  48. Map itemSub = array[index];
  49. bool isChoose = itemSub['select']??false;
  50. return GestureDetector(
  51. onTap: (){
  52. if(_isEnable==false)return;
  53. if(item['type']=='choice_single'){
  54. array.forEach((element) {
  55. element['select'] = false;
  56. });
  57. itemSub['select'] = true;
  58. }else{
  59. if(itemSub['select']==true){
  60. itemSub['select'] = false;
  61. }else{
  62. itemSub['select'] = true;
  63. }
  64. }
  65. setState(() {});
  66. },
  67. child: Container(
  68. child: Row(
  69. children: [
  70. Icon(
  71. isChoose?Icons.check_circle:Icons.radio_button_unchecked,
  72. size: 20,
  73. color: isChoose?_selectedColor:Color(0xFFD5D8DE),
  74. ),
  75. Container(
  76. width: conSize.maxWidth-20,
  77. padding: EdgeInsets.only(left: 5),
  78. child: Text(itemSub['name'],style: TextStyle(fontSize: 14,color: Color(0xFF989898)),),
  79. )
  80. ],
  81. ),
  82. ),
  83. );
  84. },
  85. separatorBuilder: (context,index){
  86. return Container(height: 10,);
  87. },
  88. itemCount: array.length,
  89. shrinkWrap: true,
  90. physics: NeverScrollableScrollPhysics(),
  91. padding: EdgeInsets.all(0),
  92. )
  93. ],
  94. );
  95. },
  96. ),
  97. );
  98. },
  99. separatorBuilder: (context,index){
  100. return Container(height: 5,color: Color(0xFFF5F3F0),);
  101. },
  102. itemCount: _dataArray.length,
  103. padding: EdgeInsets.only(top: 20),
  104. ),
  105. ),
  106. if(_isEnable)Positioned(child: GestureDetector(
  107. onTap: () async{
  108. Map request = {'id':widget.questionId};
  109. List list = [];
  110. bool isSubmit = true;
  111. _dataArray.forEach((element) {
  112. if(isSubmit==false)return;
  113. Map item = {};
  114. item['random'] = element['random'];
  115. item['type'] = element['type'];
  116. List options = element['options'];
  117. List listSub = [];
  118. options.forEach((elementSub) {
  119. if(elementSub['select']==true){
  120. listSub.add(elementSub['name']);
  121. }
  122. });
  123. if(listSub.isEmpty){
  124. ysFlutterToast(context, '${element['title']}的选项不能为空');
  125. isSubmit = false;
  126. return;
  127. }
  128. item['answers'] = listSub;
  129. list.add(item);
  130. });
  131. if(isSubmit==false)return;
  132. request['list'] = list;
  133. // LogUtil.d(request);
  134. // return;
  135. Map dict = await ysRequestHttp(context, requestType.post, 'naire/submit', request);
  136. if(dict!=null){
  137. showGeneralDialog(context: context, pageBuilder: (_,__,___){
  138. return Center(
  139. child: Container(
  140. width: MediaQuery.of(context).size.width-100,
  141. height: 150,
  142. decoration: BoxDecoration(
  143. color: Colors.white,
  144. borderRadius: BorderRadius.all(Radius.circular(10))
  145. ),
  146. child: Column(
  147. children: [
  148. Container(
  149. height: 100,
  150. decoration: BoxDecoration(
  151. border: Border(bottom: BorderSide(color: Colors.grey,width: 0.1))
  152. ),
  153. alignment: Alignment.center,
  154. child: Text('感谢您的答卷',style: TextStyle(fontSize: 14,color: Color(0xFF4A4A4A),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  155. ),
  156. GestureDetector(
  157. onTap: (){
  158. Navigator.pop(context);
  159. Navigator.pop(context);
  160. },
  161. behavior: HitTestBehavior.opaque,
  162. child: Container(
  163. height: 50,
  164. alignment: Alignment.center,
  165. child: Text('确认',style: TextStyle(fontSize: 16,color: Color(0xFFEE0A24),decoration: TextDecoration.none,fontWeight: FontWeight.normal),),
  166. ),
  167. )
  168. ],
  169. ),
  170. ),
  171. );
  172. });
  173. }
  174. },
  175. child: Container(
  176. decoration: BoxDecoration(
  177. color: Colors.pinkAccent,
  178. borderRadius: BorderRadius.all(Radius.circular(50))
  179. ),
  180. alignment: Alignment.center,
  181. child: Text('提交',style: TextStyle(fontSize: 14,color: Colors.white),),
  182. ),
  183. ),bottom: 30,left: MediaQuery.of(context).size.width/2-50,width: 100,height: 40,)
  184. ],
  185. ),
  186. );
  187. }
  188. _getQuestionData() async{
  189. Map dict = await ysRequestHttp(context, requestType.get, 'naire/info',{'naire_id':widget.questionId});
  190. if(dict!=null){
  191. _dataArray = dict['data']['questions']??'';
  192. _isEnable = dict['data']['is_can_submit']??false;
  193. if(_isEnable==false){
  194. _selectedColor = Colors.grey;
  195. }
  196. setState(() {});
  197. }
  198. }
  199. }