YSQuestionDetail.dart 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import 'package:audioplayers/audioplayers.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/cupertino.dart';
  4. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  5. import 'base/YSBase.dart';
  6. class YSQuestionDetail extends StatefulWidget {
  7. final bool isPolicy;
  8. final int questionId;
  9. const YSQuestionDetail({Key key, this.questionId,this.isPolicy}) : super(key: key);
  10. @override
  11. _YSQuestionDetailState createState() => _YSQuestionDetailState();
  12. }
  13. class _YSQuestionDetailState extends State<YSQuestionDetail> {
  14. Map _infoData;
  15. AudioPlayer audioPlayer = AudioPlayer();
  16. @override
  17. void initState() {
  18. Future.delayed(Duration(seconds: 0)).then((value){
  19. widget.isPolicy==false?_getQuestionDetailData():_getPolicyDetailData();
  20. });
  21. super.initState();
  22. }
  23. @override
  24. Widget build(BuildContext context) {
  25. return YSBase(
  26. ystitle: '问题详情',
  27. yschild: Container(
  28. decoration: BoxDecoration(
  29. color: Colors.white,
  30. borderRadius: BorderRadius.only(topLeft: Radius.circular(20),topRight: Radius.circular(20))
  31. ),
  32. child: _infoData==null?Container():SingleChildScrollView(
  33. padding: EdgeInsets.only(left: 15,right: 15,top: 20,bottom: 15),
  34. child: Column(
  35. crossAxisAlignment: CrossAxisAlignment.start,
  36. children: [
  37. Container(
  38. margin: EdgeInsets.only(bottom: 15),
  39. child: Row(
  40. children: [
  41. Container(
  42. height: 35,
  43. width: 35,
  44. decoration: BoxDecoration(
  45. color: Color(0xFFF5F3F0),
  46. borderRadius: BorderRadius.all(Radius.circular(17.5)),
  47. image: DecorationImage(image: NetworkImage('${_infoData['doctor_avatar']}'),fit: BoxFit.fill)
  48. ),
  49. ),
  50. Container(
  51. margin: EdgeInsets.only(left: 10),
  52. width: MediaQuery.of(context).size.width-85,
  53. child: Text('${_infoData['doctor_name']}医生 解答了该问题',style: TextStyle(fontSize: 14,color: Color(0xFF666666)),overflow: TextOverflow.ellipsis,),
  54. )
  55. ],
  56. ),
  57. ),
  58. Container(
  59. child: Text('标题:${_infoData['question_title']}',style: TextStyle(fontSize: 14,color: Color(0xFF292929))),
  60. ),
  61. Container(
  62. margin: EdgeInsets.only(bottom: 15,top: 15),
  63. child: Text('问:${_infoData['question_body']}',style: TextStyle(fontSize: 14,color: Color(0xFF292929)),),
  64. ),
  65. Container(
  66. width: MediaQuery.of(context).size.width-40,
  67. child: _infoData['answer_type']=='voice'?Row(
  68. children: [
  69. Text('医生解答:',style: TextStyle(fontSize: 14,color: Color(0xFF428B8D)),overflow: TextOverflow.ellipsis,),
  70. Container(
  71. height: 26,
  72. width: 59,
  73. decoration: BoxDecoration(
  74. color: Color(0xFFF5F3F0),
  75. borderRadius: BorderRadius.all(Radius.circular(4))
  76. ),
  77. alignment: Alignment.center,
  78. child: Stack(
  79. children: [
  80. Row(
  81. children: [
  82. Container(
  83. child: Image.asset('lib/images/voice2.png'),
  84. height: 15,
  85. width: 15,
  86. margin: EdgeInsets.only(left: 10,right: 5),
  87. ),
  88. Text('4',style: TextStyle(fontSize: 14,color: Color(0xFF428B8D)),overflow: TextOverflow.ellipsis,),
  89. ],
  90. )
  91. ],
  92. ),
  93. )
  94. ],
  95. ):Text('医生解答:${(_infoData['answer_body'])??''}',style: TextStyle(fontSize: 14,color: Color(0xFF428B8D)),),
  96. ),
  97. Container(
  98. margin: EdgeInsets.only(top: 15),
  99. child: Text('${_infoData['question_time']??_infoData['created_at']}',style: TextStyle(fontSize: 12,color: Color(0xFF808080))),
  100. )
  101. ],
  102. ),
  103. ),
  104. ),
  105. );
  106. }
  107. _getQuestionDetailData() async{
  108. Map dict = await ysRequestHttp(context, requestType.post, 'question/info', {'question_id':widget.questionId});
  109. if(dict!=null){
  110. setState(() {
  111. _infoData = dict['data'];
  112. });
  113. }
  114. }
  115. _getPolicyDetailData() async{
  116. Map dict = await ysRequestHttp(context, requestType.get, 'policy/info', {'id':widget.questionId});
  117. if(dict!=null){
  118. setState(() {
  119. _infoData = dict['data'];
  120. });
  121. }
  122. }
  123. play() async {
  124. audioPlayer.play(UrlSource(''));
  125. // if (result == 1) {
  126. // // success
  127. // print('play success');
  128. // } else {
  129. // print('play failed');
  130. // }
  131. }
  132. }