import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import '../../common/style/style.dart' show AppColors,Constants,ICons,MessageDetailSelects; import '../component/user_avatat.dart'; import 'package:liftmanager/widgets/load_image.dart'; import 'dart:convert'; import 'package:liftmanager/widgets/preview_images.dart'; class ChatContentView extends StatelessWidget { int type; //0 代表对方 , 1代表自己 String text;//聊天内容 String avatar;//头像url String username;//昵称 int userType;//聊天类型 2群组 1单聊 int msgType;//类型 bool isNetwork; int contentIndex; ListurlList; ChatContentView({Key key, this.type, this.text,this.avatar,this.isNetwork,this.username,this.userType=2,this.msgType,this.contentIndex,this.urlList}) : super(key: key); @override Widget build(BuildContext context) { var tapPos; //头像组件 Widget userAvatar = UserAvatar( padding: EdgeInsets.only( top: ScreenUtil().setHeight(5), right: (type == 0 ? 0.0 : ScreenUtil().setWidth(15)), left: (type == 0 ? ScreenUtil().setWidth(15) : 0.0) ), width: ScreenUtil().setWidth(40), height: ScreenUtil().setWidth(40), image: avatar!='' ? avatar: 'assets/images/temporary/avator2.png', isNetwork: isNetwork, onPressed: () {print('点击头像');} ); Widget userNameWidget = Container( margin: EdgeInsets.only(left: type == 0 ? ScreenUtil().setWidth(20) : 0,bottom: ScreenUtil().setHeight(10),right: type == 0 ? 0: ScreenUtil().setWidth(20)), child: Text(username,style: TextStyle(fontSize: ScreenUtil().setSp(14.0)),), ); Widget messageTextWidget = InkWell( onTapDown: (TapDownDetails details) { tapPos = details.globalPosition; }, onLongPress: (){ print('hehe'); }, child: Container( margin: type == 0 ? EdgeInsets.only(left:ScreenUtil().setWidth(10),right: ScreenUtil().setWidth(57)) :EdgeInsets.only(left:ScreenUtil().setWidth(57),right: ScreenUtil().setWidth(10)), child:msgType==1? Text(text, // style: TextStyle(fontSize: ScreenUtil().setSp(15.0),color: Color(0xff999999),height: 1.3), style: TextStyle(fontSize: ScreenUtil().setSp(15.0),color: Color(AppColors.TextBobule),height: 1.3), ):GestureDetector( onTap: (){ // print(JsonEncoder().convert(urlList)); // print(123456); // print("////////////////////////////"); // print(text); for(int i=0;i nameAndText = [ userNameWidget, messageTextWidget ]; final List onlyText = [ messageTextWidget ]; textBubble(){ return Expanded( child: Column( crossAxisAlignment: type == 0 ? CrossAxisAlignment.start : CrossAxisAlignment.end, children: userType == 2 && type == 0 ? nameAndText : onlyText, ) ); } return Container( margin: EdgeInsets.only(bottom: ScreenUtil().setHeight(10.0),top: ScreenUtil().setHeight(10.0)), child: type == 0 ? Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ userAvatar, textBubble() ], ) : Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ textBubble(), userAvatar, ], ) , ); } } class FadeRoute extends PageRouteBuilder { final Widget page; FadeRoute({this.page}) : super( pageBuilder: ( BuildContext context, Animation animation, Animation secondaryAnimation, ) => page, transitionsBuilder: ( BuildContext context, Animation animation, Animation secondaryAnimation, Widget child, ) => FadeTransition( opacity: animation, child: child, ), ); }