conversation_item.dart 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:flutter_slidable/flutter_slidable.dart';
  4. import '../../common/style/style.dart' show AppColors, Constants, ICons;
  5. import 'package:liftmanager/routers/fluro_navigator.dart';
  6. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  7. import 'package:liftmanager/internal/friends/model/friend_model.dart';
  8. import 'package:liftmanager/utils/time_format.dart';
  9. import 'package:liftmanager/widgets/load_image.dart';
  10. import 'package:liftmanager/utils/theme_utils.dart';
  11. import '../../friends_router.dart';
  12. import '../near_detail.dart';
  13. class ConversationItem extends StatelessWidget {
  14. ConversationItem(
  15. {this.conversationItemData,
  16. this.onTap,
  17. this.onDeleting,
  18. this.onPinning,
  19. this.onTapAvatar})
  20. : assert(conversationItemData != null);
  21. final Records conversationItemData;
  22. final Function onTap;
  23. final Function onTapAvatar;
  24. final Function onDeleting;
  25. final Function onPinning;
  26. var tapPos;
  27. @override
  28. Widget build(BuildContext context) {
  29. return Slidable(
  30. key: UniqueKey(),
  31. actionPane: SlidableDrawerActionPane(),
  32. actionExtentRatio: 0.2,
  33. secondaryActions: <Widget>[
  34. Container(
  35. color: Color(0xff555555),
  36. alignment: Alignment.center,
  37. child: GestureDetector(
  38. onTap: () {
  39. if (onPinning != null) {
  40. onPinning();
  41. }
  42. },
  43. child: Text(
  44. '置顶',
  45. style: TextStyle(fontSize: 14, color: Colors.white),
  46. ),
  47. ),
  48. ),
  49. Container(
  50. color: Color(0xffF94F45),
  51. alignment: Alignment.center,
  52. child: GestureDetector(
  53. onTap: () {
  54. if (onDeleting != null) {
  55. onDeleting();
  56. }
  57. },
  58. child: Text(
  59. '删除',
  60. style: TextStyle(fontSize: 14, color: Colors.white),
  61. ),
  62. ),
  63. )
  64. ],
  65. child: Material(
  66. color: ThemeUtils.getTabsBg(context),
  67. child: InkWell(
  68. onTap: () {
  69. onTap();
  70. },
  71. onTapDown: (TapDownDetails details) {
  72. tapPos = details.globalPosition;
  73. },
  74. onLongPress: () {},
  75. child: Container(
  76. height: 80,
  77. decoration: BoxDecoration(
  78. border: Border(
  79. bottom: BorderSide(width: .5, color: Color(0xffeeeeee))),
  80. ),
  81. child: Row(
  82. mainAxisAlignment: MainAxisAlignment.start,
  83. crossAxisAlignment: CrossAxisAlignment.center,
  84. children: <Widget>[
  85. SizedBox(width: 10),
  86. GestureDetector(
  87. onTap: () {
  88. Navigator.push(
  89. context,
  90. MaterialPageRoute(
  91. builder: (context) =>
  92. NearDetail(friendModel: conversationItemData)));
  93. },
  94. child: Container(
  95. child: ClipRRect(
  96. borderRadius: BorderRadius.circular(45.0),
  97. child: LoadNetworkImage(conversationItemData.avatarUrl),
  98. ),
  99. width: 45,
  100. height: 45,
  101. ),
  102. ),
  103. SizedBox(width: 10),
  104. Expanded(
  105. child: Container(
  106. child: contentBody(conversationItemData),
  107. ),
  108. ),
  109. SizedBox(width: 10),
  110. ],
  111. ),
  112. ),
  113. ),
  114. ),
  115. );
  116. }
  117. getCaseType(type) {
  118. String str;
  119. if (type == 1) {
  120. str = "问诊服务";
  121. } else if (type == 2) {
  122. str = "出诊服务";
  123. } else if (type == 3) {
  124. str = "附近的人";
  125. }
  126. return str;
  127. }
  128. Widget contentBody(conversationItemData) {
  129. return Column(
  130. mainAxisAlignment: MainAxisAlignment.center,
  131. crossAxisAlignment: CrossAxisAlignment.start,
  132. children: <Widget>[
  133. Row(
  134. children: <Widget>[
  135. Text(
  136. conversationItemData.remarks ??
  137. conversationItemData.userName ??
  138. "",
  139. style: TextStyle(
  140. fontSize: 16,
  141. color: Colors.black,
  142. ),
  143. maxLines: 1,
  144. overflow: TextOverflow.ellipsis,
  145. ),
  146. SizedBox(
  147. width: 10,
  148. ),
  149. Container(
  150. padding: EdgeInsets.all(2),
  151. decoration: BoxDecoration(
  152. color: Color(0xffF3F7FF),
  153. borderRadius: BorderRadius.circular(4),
  154. ),
  155. child: Text(
  156. conversationItemData.dataTable != null
  157. ? getCaseType(conversationItemData.dataTable)
  158. : "",
  159. style: TextStyle(
  160. fontSize: 12,
  161. color: Color(0xff5589FF),
  162. ),
  163. ),
  164. ),
  165. Spacer(),
  166. tips(conversationItemData)
  167. ],
  168. ),
  169. // SizedBox(height: 10),
  170. // Row(
  171. // children: <Widget>[
  172. // Text(
  173. // conversationItemData.name ?? "",
  174. // style: TextStyle(
  175. // fontSize: ScreenUtil().setSp(12.0),
  176. // color: Colors.black,
  177. // ),
  178. // maxLines: 1,
  179. // overflow: TextOverflow.ellipsis,
  180. // ),
  181. // ],
  182. // ),
  183. // SizedBox(
  184. // height: ScreenUtil().setHeight(10.0),
  185. // ),
  186. if (conversationItemData.dataTable != 3)
  187. Text(
  188. conversationItemData?.expression ?? "",
  189. style: TextStyle(
  190. fontSize: 13,
  191. color: Color(0xff666666),
  192. ),
  193. maxLines: 1,
  194. overflow: TextOverflow.ellipsis,
  195. ),
  196. if (conversationItemData.msg != null ||
  197. conversationItemData.lastMsg != null)
  198. Text(
  199. processMsg(
  200. conversationItemData.lastMsg ?? conversationItemData.msg),
  201. style: TextStyle(
  202. fontSize: 13,
  203. color: Color(0xff666666),
  204. ),
  205. maxLines: 1,
  206. overflow: TextOverflow.ellipsis,
  207. ),
  208. if (conversationItemData.isRed == 1)
  209. Row(
  210. children: [
  211. Spacer(),
  212. unreadMsgCountText(conversationItemData),
  213. ],
  214. )
  215. ],
  216. );
  217. }
  218. String processMsg(String msg) {
  219. if (msg == null) {
  220. return "";
  221. }
  222. if (msg.endsWith('.aac')) {
  223. return '「语音」';
  224. } else
  225. if (msg.contains('http://')) {
  226. return '「图片」';
  227. } else {
  228. return msg;
  229. }
  230. }
  231. Widget tips(conversationItemData) {
  232. var _rightArea = <Widget>[
  233. Text(
  234. conversationItemData.time != null
  235. ? DateUtils.instance.getFormartData(
  236. timeSamp: conversationItemData.time,
  237. format: "yyyy-MM-dd HH:mm:ss")
  238. : (conversationItemData.lastTime != null
  239. ? DateUtils.instance.getFormartData(
  240. timeSamp: conversationItemData.lastTime,
  241. format: "yyyy-MM-dd HH:mm:ss")
  242. : ""),
  243. style: TextStyle(
  244. fontSize: ScreenUtil().setSp(12.0),
  245. color: Color(AppColors.DesTextColor))),
  246. // SizedBox(height: ScreenUtil().setHeight(15.0),)
  247. ];
  248. // if(conversationItemData.isMute){
  249. // _rightArea.add(new Icon(ICons.MUTE_ICON,color: Color(AppColors.ConversationMuteIcon),size: ScreenUtil().setSp(15),));
  250. // }else{
  251. // _rightArea.add(new Icon(ICons.MUTE_ICON,color: Colors.transparent,size: ScreenUtil().setSp(15),));
  252. // }
  253. return Container(
  254. // width: ScreenUtil().setWidth(130),
  255. // margin: EdgeInsets.only(right: ScreenUtil().setWidth(10.0)),
  256. child: Column(
  257. mainAxisAlignment: MainAxisAlignment.center, children: _rightArea),
  258. );
  259. }
  260. Widget unreadMsgCountText(conversationItemData) {
  261. return Container(
  262. width: ScreenUtil().setWidth(8.0),
  263. height: ScreenUtil().setWidth(8.0),
  264. alignment: Alignment.center,
  265. decoration: BoxDecoration(
  266. borderRadius: BorderRadius.circular(16.0),
  267. color: Color(AppColors.NotifyDotBg)),
  268. // child: Text(conversationItemData.statuz.toString(),style:TextStyle(fontSize: ScreenUtil().setSp(15),color: Color(AppColors.NotifyDotText))),
  269. );
  270. }
  271. Widget muteIcon() {
  272. return new Icon(ICons.MUTE_ICON);
  273. }
  274. }