chat_content_view.dart 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import '../../common/style/style.dart' show AppColors,Constants,ICons,MessageDetailSelects;
  4. import '../component/user_avatat.dart';
  5. import 'package:liftmanager/widgets/load_image.dart';
  6. import 'dart:convert';
  7. import 'package:liftmanager/widgets/preview_images.dart';
  8. class ChatContentView extends StatelessWidget {
  9. int type; //0 代表对方 , 1代表自己
  10. String text;//聊天内容
  11. String avatar;//头像url
  12. String username;//昵称
  13. int userType;//聊天类型 2群组 1单聊
  14. int msgType;//类型
  15. bool isNetwork;
  16. int contentIndex;
  17. List<String>urlList;
  18. ChatContentView({Key key, this.type, this.text,this.avatar,this.isNetwork,this.username,this.userType=2,this.msgType,this.contentIndex,this.urlList})
  19. : super(key: key);
  20. @override
  21. Widget build(BuildContext context) {
  22. var tapPos;
  23. //头像组件
  24. Widget userAvatar = UserAvatar(
  25. padding: EdgeInsets.only(
  26. top: ScreenUtil().setHeight(5),
  27. right: (type == 0 ? 0.0 : ScreenUtil().setWidth(15)),
  28. left: (type == 0 ? ScreenUtil().setWidth(15) : 0.0)
  29. ),
  30. width: ScreenUtil().setWidth(40),
  31. height: ScreenUtil().setWidth(40),
  32. image: avatar!='' ? avatar: 'assets/images/temporary/avator2.png',
  33. isNetwork: isNetwork,
  34. onPressed: () {print('点击头像');}
  35. );
  36. Widget userNameWidget = Container(
  37. margin: EdgeInsets.only(left: type == 0 ? ScreenUtil().setWidth(20) : 0,bottom: ScreenUtil().setHeight(10),right: type == 0 ? 0: ScreenUtil().setWidth(20)),
  38. child: Text(username,style: TextStyle(fontSize: ScreenUtil().setSp(14.0)),),
  39. );
  40. Widget messageTextWidget = InkWell(
  41. onTapDown: (TapDownDetails details) {
  42. tapPos = details.globalPosition;
  43. },
  44. onLongPress: (){
  45. print('hehe');
  46. },
  47. child: Container(
  48. margin: type == 0 ? EdgeInsets.only(left:ScreenUtil().setWidth(10),right: ScreenUtil().setWidth(57)) :EdgeInsets.only(left:ScreenUtil().setWidth(57),right: ScreenUtil().setWidth(10)),
  49. child:msgType==1? Text(text,
  50. // style: TextStyle(fontSize: ScreenUtil().setSp(15.0),color: Color(0xff999999),height: 1.3),
  51. style: TextStyle(fontSize: ScreenUtil().setSp(15.0),color: Color(AppColors.TextBobule),height: 1.3),
  52. ):GestureDetector(
  53. onTap: (){
  54. // print(JsonEncoder().convert(urlList));
  55. // print(123456);
  56. // print("////////////////////////////");
  57. // print(text);
  58. for(int i=0;i<urlList.length;i++){
  59. if(urlList[i] == text){
  60. // print(urlList[i]);
  61. Navigator.of(context).push(
  62. new FadeRoute(
  63. page: PhotoViewGalleryScreen(
  64. images: urlList, //传入图片list
  65. index: i, //传入当前点击的图片的index
  66. // heroTag: img,//传入当前点击的图片的hero tag (可选)
  67. ),
  68. ),
  69. );
  70. return;
  71. }
  72. }
  73. },
  74. child: LoadNetworkImage(
  75. text,
  76. width: ScreenUtil().setWidth(100),
  77. // height: ScreenUtil().setWidth(120),
  78. ),
  79. ),
  80. padding: EdgeInsets.only(left:ScreenUtil().setWidth(8),right:ScreenUtil().setWidth(8),bottom:ScreenUtil().setHeight(8),top:ScreenUtil().setHeight(8)),
  81. decoration: BoxDecoration(
  82. borderRadius: BorderRadius.circular(5.0),
  83. color: type == 0 ? Color(0xfff5f5f5) : Color(0xfff5f5f5),
  84. boxShadow: [
  85. BoxShadow(
  86. offset: Offset(0, 0), //x,y轴
  87. color: Colors.grey[300], //投影颜色
  88. blurRadius: 2, //投影距离
  89. )
  90. ],
  91. ),
  92. ),
  93. );
  94. final List<Widget> nameAndText = [
  95. userNameWidget,
  96. messageTextWidget
  97. ];
  98. final List<Widget> onlyText = [
  99. messageTextWidget
  100. ];
  101. textBubble(){
  102. return Expanded(
  103. child: Column(
  104. crossAxisAlignment: type == 0 ? CrossAxisAlignment.start : CrossAxisAlignment.end,
  105. children: userType == 2 && type == 0 ? nameAndText : onlyText,
  106. )
  107. );
  108. }
  109. return Container(
  110. margin: EdgeInsets.only(bottom: ScreenUtil().setHeight(10.0),top: ScreenUtil().setHeight(10.0)),
  111. child: type == 0 ?
  112. Row(
  113. crossAxisAlignment: CrossAxisAlignment.start,
  114. children: <Widget>[
  115. userAvatar,
  116. textBubble()
  117. ],
  118. ) :
  119. Row(
  120. crossAxisAlignment: CrossAxisAlignment.start,
  121. children: <Widget>[
  122. textBubble(),
  123. userAvatar,
  124. ],
  125. ) ,
  126. );
  127. }
  128. }
  129. class FadeRoute extends PageRouteBuilder {
  130. final Widget page;
  131. FadeRoute({this.page})
  132. : super(
  133. pageBuilder: (
  134. BuildContext context,
  135. Animation<double> animation,
  136. Animation<double> secondaryAnimation,
  137. ) =>
  138. page,
  139. transitionsBuilder: (
  140. BuildContext context,
  141. Animation<double> animation,
  142. Animation<double> secondaryAnimation,
  143. Widget child,
  144. ) =>
  145. FadeTransition(
  146. opacity: animation,
  147. child: child,
  148. ),
  149. );
  150. }