chat_content_view.dart 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import 'dart:math';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:liftmanager/internal/friends/friends_router.dart';
  5. import 'package:liftmanager/res/iconfont.dart';
  6. import 'package:liftmanager/routers/fluro_navigator.dart';
  7. import 'package:liftmanager/widgets/load_image.dart';
  8. import 'package:liftmanager/widgets/preview_images.dart';
  9. import '../../common/style/style.dart'
  10. show AppColors, Constants, ICons, MessageDetailSelects;
  11. import '../component/user_avatat.dart';
  12. class ChatContentView extends StatelessWidget {
  13. int type; //0 代表对方 , 1代表自己
  14. String text; //聊天内容
  15. String avatar; //头像url
  16. String username; //昵称
  17. String remarks;
  18. int userType; //聊天类型 2群组 1单聊
  19. int msgType; //类型
  20. bool isNetwork;
  21. int contentIndex;
  22. List<String> urlList;
  23. int recordingDuration;
  24. Function onTap;
  25. ChatContentView(
  26. {Key key,
  27. this.type,
  28. this.text,
  29. this.avatar,
  30. this.isNetwork,
  31. this.username,
  32. this.remarks,
  33. this.userType = 2,
  34. this.msgType,
  35. this.contentIndex,
  36. this.urlList,
  37. this.recordingDuration,
  38. this.onTap})
  39. : super(key: key);
  40. @override
  41. Widget build(BuildContext context) {
  42. var tapPos;
  43. //头像组件
  44. Widget userAvatar = UserAvatar(
  45. width: 45,
  46. height: 45,
  47. image: avatar != '' ? avatar : 'assets/images/temporary/avator2.png',
  48. isNetwork: isNetwork,
  49. );
  50. Widget msgWidget;
  51. if (msgType == 1) {
  52. msgWidget = Container(
  53. padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
  54. decoration: BoxDecoration(
  55. borderRadius: BorderRadius.circular(5.0),
  56. color: type == 0 ? Color(0xffffffff) : Color(0xffE4ECFF),
  57. ),
  58. child: Text(
  59. text,
  60. style: TextStyle(
  61. fontSize: 15,
  62. color: Color(0xff333333),
  63. ),
  64. ));
  65. } else if (msgType == 2) {
  66. msgWidget = GestureDetector(
  67. onTap: () {
  68. for (int i = 0; i < urlList.length; i++) {
  69. if (urlList[i] == text) {
  70. // print(urlList[i]);
  71. Navigator.of(context).push(
  72. new FadeRoute(
  73. page: PhotoViewGalleryScreen(
  74. images: urlList, //传入图片list
  75. index: i, //传入当前点击的图片的index
  76. // heroTag: img,//传入当前点击的图片的hero tag (可选)
  77. ),
  78. ),
  79. );
  80. return;
  81. }
  82. }
  83. },
  84. child: LoadNetworkImage(
  85. text,
  86. width: ScreenUtil().setWidth(100),
  87. // height: ScreenUtil().setWidth(120),
  88. ),
  89. );
  90. } else if (msgType == 4) {
  91. msgWidget = GestureDetector(
  92. child: Container(
  93. width: 100,
  94. padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
  95. decoration: BoxDecoration(
  96. borderRadius: BorderRadius.circular(5.0),
  97. color: type == 0 ? Color(0xffffffff) : Color(0xffE4ECFF),
  98. ),
  99. child: Row(
  100. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  101. children: [
  102. Text('${recordingDuration ?? ''} "'),
  103. Transform.rotate(
  104. angle: type == 0 ? pi : 0,
  105. child: Icon(Iconfont.yuyin1, size: 20),
  106. ),
  107. ],
  108. ),
  109. ),
  110. onTap: () {
  111. if (onTap != null) {
  112. onTap();
  113. }
  114. },
  115. );
  116. }
  117. Widget messageTextWidget = InkWell(
  118. onTap: () {
  119. FocusScope.of(context).requestFocus(FocusNode());
  120. },
  121. onTapDown: (TapDownDetails details) {
  122. tapPos = details.globalPosition;
  123. },
  124. onLongPress: () {},
  125. child: Container(
  126. alignment: type == 0 ? Alignment.centerLeft : Alignment.centerRight,
  127. margin: type == 0
  128. ? EdgeInsets.only(right: ScreenUtil().setWidth(57))
  129. : EdgeInsets.only(
  130. left: ScreenUtil().setWidth(57),
  131. ),
  132. child: msgWidget),
  133. );
  134. return Container(
  135. margin: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
  136. child: Row(
  137. crossAxisAlignment: CrossAxisAlignment.start,
  138. mainAxisSize: MainAxisSize.min,
  139. children: type == 0
  140. ? [
  141. userAvatar,
  142. Container(
  143. margin: EdgeInsets.only(top: 10),
  144. child: CustomPaint(
  145. painter: _ShapesPainter(Colors.white),
  146. size: Size(10, 10),
  147. ),
  148. ),
  149. Expanded(child: messageTextWidget),
  150. ]
  151. : [
  152. Expanded(child: messageTextWidget),
  153. Container(
  154. margin: EdgeInsets.only(top: 10),
  155. child: Transform.rotate(
  156. angle: -90 * pi / 180,
  157. child: CustomPaint(
  158. painter: _ShapesPainter(Color(0xffE4ECFF)),
  159. size: Size(10, 10),
  160. ),
  161. ),
  162. ),
  163. userAvatar
  164. ],
  165. ));
  166. }
  167. }
  168. class _ShapesPainter extends CustomPainter {
  169. final Color color;
  170. _ShapesPainter(this.color);
  171. @override
  172. void paint(Canvas canvas, Size size) {
  173. final paint = Paint();
  174. paint.color = color;
  175. var path = Path();
  176. path.lineTo(size.width, 0);
  177. path.lineTo(size.height, size.width);
  178. path.close();
  179. canvas.drawPath(path, paint);
  180. }
  181. @override
  182. bool shouldRepaint(CustomPainter oldDelegate) => false;
  183. }
  184. class FadeRoute extends PageRouteBuilder {
  185. final Widget page;
  186. FadeRoute({this.page})
  187. : super(
  188. pageBuilder: (
  189. BuildContext context,
  190. Animation<double> animation,
  191. Animation<double> secondaryAnimation,
  192. ) =>
  193. page,
  194. transitionsBuilder: (
  195. BuildContext context,
  196. Animation<double> animation,
  197. Animation<double> secondaryAnimation,
  198. Widget child,
  199. ) =>
  200. FadeTransition(
  201. opacity: animation,
  202. child: child,
  203. ),
  204. );
  205. }