YSAskQuestion.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  4. import 'package:shared_preferences/shared_preferences.dart';
  5. import 'YSDoctorDetail.dart';
  6. import 'base/YSBase.dart';
  7. class YSAskQuestion extends StatefulWidget {
  8. final Map info;
  9. final bool isPolicy;
  10. const YSAskQuestion({Key key, this.info,this.isPolicy}) : super(key: key);
  11. @override
  12. _YSAskQuestionState createState() => _YSAskQuestionState();
  13. }
  14. class _YSAskQuestionState extends State<YSAskQuestion> {
  15. int selected = 0;
  16. TextEditingController _title = TextEditingController();
  17. TextEditingController _content = TextEditingController();
  18. @override
  19. Widget build(BuildContext context) {
  20. return YSBase(
  21. ystitle: '提问',
  22. yschild: SingleChildScrollView(
  23. physics: NeverScrollableScrollPhysics(),
  24. child: Column(
  25. children: [
  26. Container(
  27. height: MediaQuery.of(context).size.height-155,
  28. child: SingleChildScrollView(
  29. child: Column(
  30. children: [
  31. GestureDetector(
  32. onTap: (){
  33. Navigator.of(context).push(
  34. CupertinoPageRoute(
  35. builder: (context){
  36. return YSDoctorDetail(doctorId: widget.info['id'],isPolicy: widget.isPolicy,);
  37. }
  38. )
  39. );
  40. },
  41. child: Container(
  42. height: 150,
  43. decoration: BoxDecoration(borderRadius: BorderRadius.only(topLeft: Radius.circular(20),topRight: Radius.circular(20)),color: Colors.white,),
  44. padding: EdgeInsets.only(left: 15,right: 15),
  45. child: Row(
  46. children: [
  47. Container(
  48. height: 120,
  49. width: 100,
  50. decoration: BoxDecoration(
  51. color: Color(0xFF41898C),
  52. borderRadius: BorderRadius.all(Radius.circular(5)),
  53. image: DecorationImage(image: NetworkImage('${widget.info['avatar']}'),fit: BoxFit.fill)
  54. ),
  55. ),
  56. Container(
  57. height: 120,
  58. margin: EdgeInsets.only(left: 10),
  59. child: Column(
  60. children: [
  61. Container(
  62. child: Text('${widget.info['name']}',style: TextStyle(fontSize: 16,color: Color(0xFF292929),fontWeight: FontWeight.w600),overflow: TextOverflow.ellipsis,),
  63. width: MediaQuery.of(context).size.width-140,
  64. margin: EdgeInsets.only(bottom: 5,top: 5),
  65. ),
  66. Container(
  67. child: Text('${widget.info['introduction']}',
  68. style: TextStyle(fontSize: 12,color: Color(0xFF808080),fontWeight: FontWeight.normal),overflow: TextOverflow.ellipsis,maxLines: 5,),
  69. width: MediaQuery.of(context).size.width-140,
  70. )
  71. ],
  72. ),
  73. )
  74. ],
  75. ),
  76. ),
  77. ),
  78. Container(
  79. width: MediaQuery.of(context).size.width,
  80. color: Colors.white,
  81. margin: EdgeInsets.all(5),
  82. padding: EdgeInsets.all(15),
  83. child: Column(
  84. crossAxisAlignment: CrossAxisAlignment.start,
  85. children: [
  86. Container(
  87. child: Row(
  88. children: [
  89. GestureDetector(
  90. onTap: (){
  91. setState(() {
  92. selected = 0;
  93. });
  94. },
  95. child: Container(
  96. margin: EdgeInsets.only(right: 20, bottom: 5),
  97. child: Text('公开',style: TextStyle(color: selected==0?Color(0xFFDB5279):Color(0xFF292929),fontSize: 14,decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  98. ),
  99. ),
  100. GestureDetector(
  101. onTap: (){
  102. setState(() {
  103. selected = 1;
  104. });
  105. },
  106. child: Container(
  107. margin: EdgeInsets.only(bottom: 5),
  108. child: Text('私密',style: TextStyle(color: selected==1?Color(0xFFDB5279):Color(0xFF292929),fontSize: 14,decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  109. ),
  110. )
  111. ],
  112. ),
  113. ),
  114. Container(height: 2,width: 15,color: Color(0xFFDB5279),margin: EdgeInsets.only(left: selected==0?7:55),),
  115. Container(
  116. margin: EdgeInsets.only(top: 10),
  117. width: MediaQuery.of(context).size.width,
  118. height: 1.5,
  119. child: Image.asset('lib/images/line.png'),
  120. ),
  121. Container(
  122. height: 50,
  123. child: Row(
  124. children: [
  125. Text('标题',style: TextStyle(fontSize: 15,color: Color(0xFF292929),fontWeight: FontWeight.w600),),
  126. Container(
  127. height: 30,
  128. margin: EdgeInsets.only(left: 10),
  129. width: MediaQuery.of(context).size.width-90,
  130. child: CupertinoTextField(
  131. placeholder: '请输入问题梗概',
  132. style: TextStyle(fontSize: 14,color: Color(0xFF292929)),
  133. placeholderStyle: TextStyle(fontSize: 14,color: Color(0xFF808080)),
  134. decoration: BoxDecoration(),
  135. controller: _title,
  136. ),
  137. )
  138. ],
  139. ),
  140. ),
  141. Container(
  142. margin: EdgeInsets.only(bottom: 10),
  143. width: MediaQuery.of(context).size.width,
  144. height: 1.5,
  145. child: Image.asset('lib/images/line.png'),
  146. ),
  147. Text('详情',style: TextStyle(fontSize: 15,color: Color(0xFF292929),fontWeight: FontWeight.w600),),
  148. Container(
  149. height: 180,
  150. child: CupertinoTextField(
  151. placeholder: '请输入问题内容(10-500个字内)',
  152. style: TextStyle(fontSize: 14,color: Color(0xFF292929)),
  153. placeholderStyle: TextStyle(fontSize: 14,color: Color(0xFF808080)),
  154. decoration: BoxDecoration(),
  155. maxLines: 1000,
  156. maxLength: 500,
  157. controller: _content,
  158. ),
  159. )
  160. ],
  161. ),
  162. ),
  163. ],
  164. ),
  165. ),
  166. ),
  167. Container(
  168. height: 70,
  169. width: MediaQuery.of(context).size.width,
  170. color: Colors.white,
  171. child: CupertinoButton(
  172. padding: EdgeInsets.only(top: 5),
  173. child: Container(
  174. width: MediaQuery.of(context).size.width-150,
  175. height: 40,
  176. decoration: BoxDecoration(
  177. color: Color(0xFFEA6C8F),
  178. borderRadius: BorderRadius.all(Radius.circular(20))
  179. ),
  180. alignment: Alignment.center,
  181. child: Text('提交',style: TextStyle(fontSize: 16,color: Colors.white,decoration: TextDecoration.none),),
  182. ),
  183. onPressed: (){
  184. _postAnswerData();
  185. },
  186. )
  187. )
  188. ],
  189. ),
  190. ),
  191. );
  192. }
  193. _postAnswerData() async{
  194. if(_title.text.isEmpty){
  195. ysFlutterToast(context, '请输入标题');
  196. return;
  197. }
  198. if(_content.text.length<10||_content.text.length>500){
  199. ysFlutterToast(context, '内容应该为10-500个字内');
  200. return;
  201. }
  202. Map request = Map();
  203. request['question_title'] = _title.text;
  204. request['question_body'] = _content.text;
  205. request['is_show'] = selected==0?1:0;
  206. if(widget.isPolicy==false){
  207. SharedPreferences prefer = await SharedPreferences.getInstance();
  208. request['category_id'] = prefer.getInt('chapters');
  209. request['hospital_doctor_id'] = widget.info['id'];
  210. }else{
  211. request['question_doctor_id'] = widget.info['id'];
  212. request['question_area_id'] = widget.info['area_id'];
  213. }
  214. Map dict = await ysRequestHttp(context, requestType.post, widget.isPolicy==false?'question/ask':'policy/ask', request);
  215. if(dict!=null){
  216. ysFlutterToast(context, '问题提交成功,等待医师回复');
  217. _title.text = '';
  218. _content.text = '';
  219. }
  220. }
  221. }