diff --git a/lib/community/community_view/community_dynamic.dart b/lib/community/community_view/community_dynamic.dart index 9705d1ff..cbb7949b 100644 --- a/lib/community/community_view/community_dynamic.dart +++ b/lib/community/community_view/community_dynamic.dart @@ -19,7 +19,6 @@ import 'package:video_player/video_player.dart'; import '../photo_view_gallery_screen.dart'; - class CommunityDynamic extends StatefulWidget { final int itemCount; final Function(double height) heightFun; @@ -77,11 +76,9 @@ class _CommunityDynamic extends State { String filePath; initVideo() async { - if(widget?.article?.content == null) - return; + if (widget?.article?.content == null) return; var cnt = jsonDecode(widget.article.content); - if (cnt["type"] == "video" && - cnt["video"] != null) { + if (cnt["type"] == "video" && cnt["video"] != null) { if (widget.isList) { videoPlayerController = VideoPlayerController.network( cnt["video"], @@ -116,11 +113,12 @@ class _CommunityDynamic extends State { } ///关注/取关会员 - _vipFollow(followId,isFollow) async { + _vipFollow(followId, isFollow) async { BaseData baseData = await apiService.follow(followId); if (baseData != null && baseData.isSuccess) { widget.exitFull(); - SmartDialog.showToast(isFollow?"关注成功":"取关成功", alignment: Alignment.center); + SmartDialog.showToast(isFollow ? "关注成功" : "取关成功", + alignment: Alignment.center); setState(() {}); } else { // SmartDialog.showToast(baseData.msg, alignment: Alignment.center); @@ -173,22 +171,29 @@ class _CommunityDynamic extends State { child: Row( children: [ GestureDetector( - onTap: (){ - Navigator.push(context, MaterialPageRoute( builder: (context) => PhotoViewGalleryScreen( - images:[widget?.article?.authorHeadImg ?? "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg"],//传入图片list - index: 0,//传入当前点击的图片的index - ), )); - }, - child: MImage( - (widget?.article?.authorHeadImg ?? "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg") + "?imageView2/1/w/200/h/200/format/jpg/q/75", - width: 44, - height: 44, - isCircle: true, - fit: BoxFit.cover, - errorSrc: "assets/image/default_1.png", - fadeSrc: "assets/image/default_1.png", - ), - ), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PhotoViewGalleryScreen( + images: [(widget?.article?.authorHeadImg ?? "").isEmpty? + "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg":widget?.article?.authorHeadImg + ], //传入图片list + index: 0, //传入当前点击的图片的index + ), + )); + }, + child: + MImage( + (widget?.article?.authorHeadImg ?? "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg") + "?imageView2/1/w/200/h/200/format/jpg/q/75", + width: 44, + height: 44, + isCircle: true, + fit: BoxFit.cover, + errorSrc: "assets/image/default_1.png", + fadeSrc: "assets/image/default_1.png", + ), + ), SizedBox( width: 8, ), @@ -224,7 +229,8 @@ class _CommunityDynamic extends State { if (widget.commentType == 0) { widget.article.liked = !(widget.article.liked ?? false); - _vipFollow(widget.article.updateUser,widget.article.liked ?? false); + _vipFollow(widget.article.updateUser, + widget.article.liked ?? false); } else { showDeleteDialog(); } @@ -257,11 +263,14 @@ class _CommunityDynamic extends State { size: 15, ), )) - : Padding(padding: EdgeInsets.all(20),child:Icon( - Icons.close, - color: Colors.black, - size: 16, - ),), + : Padding( + padding: EdgeInsets.all(20), + child: Icon( + Icons.close, + color: Colors.black, + size: 16, + ), + ), ), ], ), @@ -340,34 +349,41 @@ class _CommunityDynamic extends State { } var cnt = jsonDecode(subjectInfo); Widget itemWidget = Container(); - if (cnt["type"] == "image"&& cnt["images"] != null && cnt["images"].length > 0) { + if (cnt["type"] == "image" && + cnt["images"] != null && + cnt["images"].length > 0) { if (cnt["images"].length == 1) { itemWidget = Container( child: InkWell( - onTap: () { - // ImagePickers.previewImages(subjectInfo.images,0); - Navigator.push(context, MaterialPageRoute( builder: (context) => PhotoViewGalleryScreen( - images:cnt["images"],//传入图片list - index: 0,//传入当前点击的图片的index - ), ), ); - }, - child: MImage( - cnt["images"][0].replaceAll(".jpg",".jpg?imageView2/0/q/75"), - fit: BoxFit.cover, - radius: BorderRadius.circular(2), - width: MediaQuery.of(context).size.width, - height: MediaQuery.of(context).size.width, - errorSrc: "assets/image/default_2_1.png", - fadeSrc: "assets/image/default_2_1.png", - )), + onTap: () { + // ImagePickers.previewImages(subjectInfo.images,0); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PhotoViewGalleryScreen( + images: cnt["images"], //传入图片list + index: 0, //传入当前点击的图片的index + ), + ), + ); + }, + child: MImage( + cnt["images"][0].replaceAll(".jpg", ".jpg?imageView2/0/q/75"), + fit: BoxFit.contain, + radius: BorderRadius.circular(2), + width: MediaQuery.of(context).size.width/1.5, + height:MediaQuery.of(context).size.width, + errorSrc: "assets/image/default_2_1.png", + fadeSrc: "assets/image/default_2_1.png", + )), ); } else { itemWidget = GridView.builder( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: (cnt["images"].length == 2 || - cnt["images"].length == 4) - ? 2 - : 3, + crossAxisCount: + (cnt["images"].length == 2 || cnt["images"].length == 4) + ? 2 + : 3, crossAxisSpacing: 12.w, mainAxisSpacing: 12.w, childAspectRatio: 1, @@ -380,13 +396,19 @@ class _CommunityDynamic extends State { child: InkWell( onTap: () { // ImagePickers.previewImages(subjectInfo.images, position); - Navigator.push(context, MaterialPageRoute( builder: (context) => PhotoViewGalleryScreen( - images:cnt["images"],//传入图片list - index: position,//传入当前点击的图片的index - ), ), ); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => PhotoViewGalleryScreen( + images: cnt["images"], //传入图片list + index: position, //传入当前点击的图片的index + ), + ), + ); }, child: MImage( - cnt["images"][position].replaceAll(".jpg",".jpg?imageView2/0/q/75"), + cnt["images"][position] + .replaceAll(".jpg", ".jpg?imageView2/0/q/75"), fit: BoxFit.cover, aspectRatio: 1, radius: BorderRadius.circular(1), @@ -399,15 +421,16 @@ class _CommunityDynamic extends State { itemCount: cnt["images"].length, ); } - } - else if (cnt["type"] == "video" && cnt["video"]!= null && cnt["video"].isNotEmpty) { + } else if (cnt["type"] == "video" && + cnt["video"] != null && + cnt["video"].isNotEmpty) { itemWidget = videoWidget( MediaQuery.of(context).size.width - 32, videoPlayerController != null ? (MediaQuery.of(context).size.width - 32) / videoPlayerController.value.aspectRatio : MediaQuery.of(context).size.width / 2, - cnt["video"].replaceAll(".mp4","_poster.jpg"), + cnt["video"].replaceAll(".mp4", "_poster.jpg"), ); } return Column( @@ -459,8 +482,8 @@ class _CommunityDynamic extends State { height: height, )) : Container( - width: MediaQuery.of(context).size.width, - height:MediaQuery.of(context).size.width, + width: width, + height: width / 7 * 5, color: Colors.black, child: Stack( children: [ diff --git a/lib/view_widget/custom_image.dart b/lib/view_widget/custom_image.dart index dbe05a58..de07a63d 100644 --- a/lib/view_widget/custom_image.dart +++ b/lib/view_widget/custom_image.dart @@ -34,12 +34,15 @@ class MImage extends StatelessWidget { Widget image = LayoutBuilder( builder: (context, constraints) { String imageUrl = ""; + ///压缩图片 if (src != null && src != "" && src.startsWith("http")) { + String oper = src.contains("?") ? "" :"?"; imageUrl = - "$src?imageMogr2/thumbnail/${constraints.constrainWidth() * scaleIndex}" + "$src$oper/imageMogr2/thumbnail/${constraints.constrainWidth() * scaleIndex}" "x${constraints.constrainHeight() * scaleIndex}/format/webp/quality/100"; } + // print(imageUrl); // print("constrainWidth: ${constraints.constrainWidth()}"); // print("constrainHeight: ${constraints.constrainHeight()}");