conversation_item.dart 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  4. import 'package:liftmanager/routers/fluro_navigator.dart';
  5. import '../../common/style/style.dart' show AppColors,Constants,ICons;
  6. import '../../model/conversation.dart';
  7. // import '../../routers/application.dart';
  8. class ConversationItem extends StatelessWidget {
  9. ConversationItem(this.conversationItemData,this.index,this.type)
  10. :assert(conversationItemData != null);
  11. int index;
  12. int type;
  13. final Conversation conversationItemData;
  14. var tapPos;
  15. @override
  16. Widget build(BuildContext context) {
  17. return Material(
  18. color: Color(AppColors.ConversationItemBg),
  19. child: InkWell(
  20. onTap: (){
  21. print('打开会话:${conversationItemData.title}');
  22. // Application.router.navigateTo(context, '/chatdetail?index=${index}&type=${type}');
  23. NavigatorUtils.push(context, BbsRouter.chatRoom);
  24. },
  25. onTapDown: (TapDownDetails details) {
  26. tapPos = details.globalPosition;
  27. },
  28. onLongPress: (){
  29. _showMenu(context,tapPos);
  30. print('弹出会话菜单:${conversationItemData.title}');
  31. },
  32. child: Container(
  33. height: ScreenUtil().setHeight(120),
  34. child: Row(
  35. mainAxisAlignment: MainAxisAlignment.center,
  36. children: <Widget>[
  37. avatarContainer(conversationItemData),
  38. Content(),
  39. ],
  40. ),
  41. ),
  42. ),
  43. );
  44. }
  45. _showMenu(BuildContext context,Offset tapPos){
  46. final RenderBox overlay =Overlay.of(context).context.findRenderObject();
  47. final RelativeRect position = RelativeRect.fromLTRB(
  48. tapPos.dx, tapPos.dy,
  49. overlay.size.width - tapPos.dx,
  50. overlay.size.height - tapPos.dy
  51. );
  52. showMenu<String>(
  53. context: context,
  54. position: position,
  55. items: <PopupMenuItem<String>>[
  56. PopupMenuItem(
  57. child: Text(Constants.MENU_MARK_AS_UNREAD_VALUE),
  58. value: Constants.MENU_MARK_AS_UNREAD,
  59. ),
  60. PopupMenuItem(
  61. child: Text(Constants.MENU_PIN_TO_TOP_VALUE),
  62. value: Constants.MENU_PIN_TO_TOP,
  63. ),
  64. PopupMenuItem(
  65. child: Text(Constants.MENU_DELETE_CONVERSATION_VALUE),
  66. value: Constants.MENU_DELETE_CONVERSATION,
  67. ),
  68. ]
  69. ).then<String>((String selected) {
  70. switch(selected){
  71. default:
  72. print('当前选中的是:$selected');
  73. }
  74. });
  75. }
  76. Widget Content(){
  77. return Expanded(
  78. child: Container(
  79. height: ScreenUtil().setHeight(120),
  80. margin: EdgeInsets.only(left:ScreenUtil().setWidth(20.0)),
  81. decoration: BoxDecoration(
  82. border: Border(
  83. bottom: BorderSide(width: 0.5,color: Color(AppColors.DividerColor),)
  84. )
  85. ),
  86. child: Row(
  87. children: <Widget>[
  88. Title(conversationItemData),
  89. Tip(conversationItemData)
  90. ],
  91. ),
  92. ),
  93. );
  94. }
  95. Widget ClipRRectImg(){
  96. return ClipRRect(
  97. borderRadius: BorderRadius.circular(5.0),
  98. child: conversationItemData.isAvatarFromNet() ? Image.network(conversationItemData.avatar,scale: 1.0, fit: BoxFit.cover,) : Image.asset(conversationItemData.avatar, fit: BoxFit.cover,),
  99. );
  100. }
  101. Widget Avatar(conversationItemData){
  102. return Container(
  103. margin: EdgeInsets.only(left:ScreenUtil().setWidth(20.0)),
  104. child: ClipRRectImg(),
  105. width: ScreenUtil().setWidth(100),
  106. height: ScreenUtil().setWidth(100)
  107. );
  108. }
  109. Widget Title(conversationItemData){
  110. return Expanded(
  111. child: Column(
  112. mainAxisAlignment: MainAxisAlignment.center,
  113. crossAxisAlignment: CrossAxisAlignment.start,
  114. children: <Widget>[
  115. Text(
  116. conversationItemData.title,
  117. style: TextStyle(fontSize: ScreenUtil().setSp(30.0),color: Color(AppColors.TitleColor),fontWeight:FontWeight.w400),
  118. maxLines: 1,
  119. overflow: TextOverflow.ellipsis,
  120. ),
  121. SizedBox(height: ScreenUtil().setHeight(15.0),),
  122. Text(
  123. conversationItemData.des,
  124. style: TextStyle(fontSize: ScreenUtil().setSp(24.0),color: Color(AppColors.DesTextColor)),
  125. maxLines: 1,
  126. overflow: TextOverflow.ellipsis,
  127. )
  128. ],
  129. ),
  130. );
  131. }
  132. Widget Tip(conversationItemData){
  133. var _rightArea =<Widget>[
  134. Text(conversationItemData.updateAt,style:TextStyle(fontSize: ScreenUtil().setSp(24.0),color: Color(AppColors.DesTextColor))),
  135. SizedBox(height: ScreenUtil().setHeight(15.0),)
  136. ];
  137. if(conversationItemData.isMute){
  138. _rightArea.add(new Icon(ICons.MUTE_ICON,color: Color(AppColors.ConversationMuteIcon),size: ScreenUtil().setSp(30),));
  139. }else{
  140. _rightArea.add(new Icon(ICons.MUTE_ICON,color: Colors.transparent,size: ScreenUtil().setSp(30),));
  141. }
  142. return Container(
  143. width:ScreenUtil().setWidth(80),
  144. margin: EdgeInsets.only(right: ScreenUtil().setWidth(10.0)),
  145. child: Column(
  146. mainAxisAlignment: MainAxisAlignment.center,
  147. children: _rightArea
  148. ),
  149. );
  150. }
  151. Widget avatarContainer(conversationItemData){
  152. if(conversationItemData.unreadMsgCount > 0){
  153. return Stack(
  154. overflow: Overflow.visible,
  155. children: <Widget>[
  156. Avatar(conversationItemData),
  157. Positioned(
  158. right:-3.0 ,
  159. top: -3.0,
  160. child: unreadMsgCountText(conversationItemData),
  161. )
  162. ],
  163. );
  164. }else{
  165. return Avatar(conversationItemData);
  166. }
  167. }
  168. Widget unreadMsgCountText(conversationItemData){
  169. return Container(
  170. width: ScreenUtil().setWidth(32.0),
  171. height: ScreenUtil().setWidth(32.0),
  172. alignment: Alignment.center,
  173. decoration: BoxDecoration(
  174. borderRadius: BorderRadius.circular(35.0),
  175. color: Color(AppColors.NotifyDotBg)
  176. ),
  177. child: Text(conversationItemData.unreadMsgCount.toString(),style:TextStyle(fontSize: ScreenUtil().setSp(18),color: Color(AppColors.NotifyDotText))),
  178. );
  179. }
  180. Widget muteIcon(){
  181. return new Icon(ICons.MUTE_ICON);
  182. }
  183. }