import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutterappfuyou/code/base/YSNetWorking.dart'; import '../../YSQuestionDetail.dart'; class YSQuestionListView extends StatefulWidget { final Map questionItem; const YSQuestionListView({Key key, this.questionItem}) : super(key: key); @override _YSQuestionListViewState createState() => _YSQuestionListViewState(); } class _YSQuestionListViewState extends State { @override Widget build(BuildContext context) { return GestureDetector( onTap: (){ Navigator.of(context).push( CupertinoPageRoute( builder: (context){ return YSQuestionDetail(questionId: widget.questionItem['id'],isPolicy: false,); } ) ); }, child: Container( margin: EdgeInsets.only(left: 5,right: 5), padding: EdgeInsets.all(15), height: 160, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(6)) ), child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ Container( height: 35, width: 35, decoration: BoxDecoration( color: Color(0xFFF5F3F0), borderRadius: BorderRadius.all(Radius.circular(17.5)), image: DecorationImage(image: NetworkImage('${widget.questionItem['doctor_avatar']}'),fit: BoxFit.fill) ), ), Container( margin: EdgeInsets.only(left: 10), width: MediaQuery.of(context).size.width-85, child: Text('${widget.questionItem['doctor_name']}医生 解答了该问题',style: TextStyle(fontSize: 14,color: Color(0xFF666666)),overflow: TextOverflow.ellipsis,), ) ], ), Container( width: MediaQuery.of(context).size.width-40, child: Text('问:${widget.questionItem['question_title']}',style: TextStyle(fontSize: 14,color: Color(0xFF292929)),overflow: TextOverflow.ellipsis,), ), Container( width: MediaQuery.of(context).size.width-40, child: widget.questionItem['answer_type']=='voice'?Row( children: [ Text('医生解答:',style: TextStyle(fontSize: 14,color: Color(0xFF428B8D)),overflow: TextOverflow.ellipsis,), Container( height: 26, width: 59, decoration: BoxDecoration( color: Color(0xFFF5F3F0), borderRadius: BorderRadius.all(Radius.circular(4)) ), alignment: Alignment.center, child: Stack( children: [ Row( children: [ Container( child: Image.asset('lib/images/voice2.png'), height: 15, width: 15, margin: EdgeInsets.only(left: 10,right: 5), ), Text('4',style: TextStyle(fontSize: 14,color: Color(0xFF428B8D)),overflow: TextOverflow.ellipsis,), ], ) ], ), ) ], ):Text('医生解答:${(widget.questionItem['answer_body'])??''}',style: TextStyle(fontSize: 14,color: Color(0xFF428B8D)),overflow: TextOverflow.ellipsis,), ), Container( width: MediaQuery.of(context).size.width, height: 1.5, child: Image.asset('lib/images/line.png'), ), Row( children: [ Container( width: MediaQuery.of(context).size.width-85, child: Text('${widget.questionItem['question_time']}',style: TextStyle(fontSize: 12,color: Color(0xFF808080)),overflow: TextOverflow.ellipsis,), ), GestureDetector( child: Image(height: 15,width: 15,image: AssetImage(widget.questionItem['is_favorite']==false?'lib/images/uncollection.png':'lib/images/collection.png'),), onTap: () async{ _postCollectionData(); }, ) ], mainAxisAlignment: MainAxisAlignment.spaceBetween, ) ], ), ), ); } _postCollectionData() async{ Map dict = await ysRequestHttpNoLoading(context, requestType.post, 'question/favorite', {'question_id':widget.questionItem['id']}); if(dict!=null){ widget.questionItem['is_favorite'] = dict['data']['is_favorite']; setState(() {}); } } }