Browse Source

图片优化更改

ff_new
w-R 3 years ago
parent
commit
b4376dd793
  1. 143
      lib/community/community_view/community_dynamic.dart
  2. 5
      lib/view_widget/custom_image.dart

143
lib/community/community_view/community_dynamic.dart

@ -19,7 +19,6 @@ import 'package:video_player/video_player.dart';
import '../photo_view_gallery_screen.dart'; import '../photo_view_gallery_screen.dart';
class CommunityDynamic extends StatefulWidget { class CommunityDynamic extends StatefulWidget {
final int itemCount; final int itemCount;
final Function(double height) heightFun; final Function(double height) heightFun;
@ -77,11 +76,9 @@ class _CommunityDynamic extends State<CommunityDynamic> {
String filePath; String filePath;
initVideo() async { initVideo() async {
if(widget?.article?.content == null) if (widget?.article?.content == null) return;
return;
var cnt = jsonDecode(widget.article.content); var cnt = jsonDecode(widget.article.content);
if (cnt["type"] == "video" && if (cnt["type"] == "video" && cnt["video"] != null) {
cnt["video"] != null) {
if (widget.isList) { if (widget.isList) {
videoPlayerController = VideoPlayerController.network( videoPlayerController = VideoPlayerController.network(
cnt["video"], cnt["video"],
@ -116,11 +113,12 @@ class _CommunityDynamic extends State<CommunityDynamic> {
} }
//// ////
_vipFollow(followId,isFollow) async { _vipFollow(followId, isFollow) async {
BaseData baseData = await apiService.follow(followId); BaseData baseData = await apiService.follow(followId);
if (baseData != null && baseData.isSuccess) { if (baseData != null && baseData.isSuccess) {
widget.exitFull(); widget.exitFull();
SmartDialog.showToast(isFollow?"关注成功":"取关成功", alignment: Alignment.center); SmartDialog.showToast(isFollow ? "关注成功" : "取关成功",
alignment: Alignment.center);
setState(() {}); setState(() {});
} else { } else {
// SmartDialog.showToast(baseData.msg, alignment: Alignment.center); // SmartDialog.showToast(baseData.msg, alignment: Alignment.center);
@ -173,22 +171,29 @@ class _CommunityDynamic extends State<CommunityDynamic> {
child: Row( child: Row(
children: [ children: [
GestureDetector( GestureDetector(
onTap: (){ onTap: () {
Navigator.push(context, MaterialPageRoute( builder: (context) => PhotoViewGalleryScreen( Navigator.push(
images:[widget?.article?.authorHeadImg ?? "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg"],//list context,
index: 0,//index MaterialPageRoute(
), )); builder: (context) => PhotoViewGalleryScreen(
}, images: [(widget?.article?.authorHeadImg ?? "").isEmpty?
child: MImage( "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg":widget?.article?.authorHeadImg
(widget?.article?.authorHeadImg ?? "https://lmg.jj20.com/up/allimg/tx30/09041130358711081.jpg") + "?imageView2/1/w/200/h/200/format/jpg/q/75", ], //list
width: 44, index: 0, //index
height: 44, ),
isCircle: true, ));
fit: BoxFit.cover, },
errorSrc: "assets/image/default_1.png", child:
fadeSrc: "assets/image/default_1.png", 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( SizedBox(
width: 8, width: 8,
), ),
@ -224,7 +229,8 @@ class _CommunityDynamic extends State<CommunityDynamic> {
if (widget.commentType == 0) { if (widget.commentType == 0) {
widget.article.liked = widget.article.liked =
!(widget.article.liked ?? false); !(widget.article.liked ?? false);
_vipFollow(widget.article.updateUser,widget.article.liked ?? false); _vipFollow(widget.article.updateUser,
widget.article.liked ?? false);
} else { } else {
showDeleteDialog(); showDeleteDialog();
} }
@ -257,11 +263,14 @@ class _CommunityDynamic extends State<CommunityDynamic> {
size: 15, size: 15,
), ),
)) ))
: Padding(padding: EdgeInsets.all(20),child:Icon( : Padding(
Icons.close, padding: EdgeInsets.all(20),
color: Colors.black, child: Icon(
size: 16, Icons.close,
),), color: Colors.black,
size: 16,
),
),
), ),
], ],
), ),
@ -340,34 +349,41 @@ class _CommunityDynamic extends State<CommunityDynamic> {
} }
var cnt = jsonDecode(subjectInfo); var cnt = jsonDecode(subjectInfo);
Widget itemWidget = Container(); 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) { if (cnt["images"].length == 1) {
itemWidget = Container( itemWidget = Container(
child: InkWell( child: InkWell(
onTap: () { onTap: () {
// ImagePickers.previewImages(subjectInfo.images,0); // ImagePickers.previewImages(subjectInfo.images,0);
Navigator.push(context, MaterialPageRoute( builder: (context) => PhotoViewGalleryScreen( Navigator.push(
images:cnt["images"],//list context,
index: 0,//index MaterialPageRoute(
), ), ); builder: (context) => PhotoViewGalleryScreen(
}, images: cnt["images"], //list
child: MImage( index: 0, //index
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, child: MImage(
errorSrc: "assets/image/default_2_1.png", cnt["images"][0].replaceAll(".jpg", ".jpg?imageView2/0/q/75"),
fadeSrc: "assets/image/default_2_1.png", 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 { } else {
itemWidget = GridView.builder( itemWidget = GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: (cnt["images"].length == 2 || crossAxisCount:
cnt["images"].length == 4) (cnt["images"].length == 2 || cnt["images"].length == 4)
? 2 ? 2
: 3, : 3,
crossAxisSpacing: 12.w, crossAxisSpacing: 12.w,
mainAxisSpacing: 12.w, mainAxisSpacing: 12.w,
childAspectRatio: 1, childAspectRatio: 1,
@ -380,13 +396,19 @@ class _CommunityDynamic extends State<CommunityDynamic> {
child: InkWell( child: InkWell(
onTap: () { onTap: () {
// ImagePickers.previewImages(subjectInfo.images, position); // ImagePickers.previewImages(subjectInfo.images, position);
Navigator.push(context, MaterialPageRoute( builder: (context) => PhotoViewGalleryScreen( Navigator.push(
images:cnt["images"],//list context,
index: position,//index MaterialPageRoute(
), ), ); builder: (context) => PhotoViewGalleryScreen(
images: cnt["images"], //list
index: position, //index
),
),
);
}, },
child: MImage( 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, fit: BoxFit.cover,
aspectRatio: 1, aspectRatio: 1,
radius: BorderRadius.circular(1), radius: BorderRadius.circular(1),
@ -399,15 +421,16 @@ class _CommunityDynamic extends State<CommunityDynamic> {
itemCount: cnt["images"].length, itemCount: cnt["images"].length,
); );
} }
} } else if (cnt["type"] == "video" &&
else if (cnt["type"] == "video" && cnt["video"]!= null && cnt["video"].isNotEmpty) { cnt["video"] != null &&
cnt["video"].isNotEmpty) {
itemWidget = videoWidget( itemWidget = videoWidget(
MediaQuery.of(context).size.width - 32, MediaQuery.of(context).size.width - 32,
videoPlayerController != null videoPlayerController != null
? (MediaQuery.of(context).size.width - 32) / ? (MediaQuery.of(context).size.width - 32) /
videoPlayerController.value.aspectRatio videoPlayerController.value.aspectRatio
: MediaQuery.of(context).size.width / 2, : MediaQuery.of(context).size.width / 2,
cnt["video"].replaceAll(".mp4","_poster.jpg"), cnt["video"].replaceAll(".mp4", "_poster.jpg"),
); );
} }
return Column( return Column(
@ -459,8 +482,8 @@ class _CommunityDynamic extends State<CommunityDynamic> {
height: height, height: height,
)) ))
: Container( : Container(
width: MediaQuery.of(context).size.width, width: width,
height:MediaQuery.of(context).size.width, height: width / 7 * 5,
color: Colors.black, color: Colors.black,
child: Stack( child: Stack(
children: [ children: [

5
lib/view_widget/custom_image.dart

@ -34,12 +34,15 @@ class MImage extends StatelessWidget {
Widget image = LayoutBuilder( Widget image = LayoutBuilder(
builder: (context, constraints) { builder: (context, constraints) {
String imageUrl = ""; String imageUrl = "";
///
if (src != null && src != "" && src.startsWith("http")) { if (src != null && src != "" && src.startsWith("http")) {
String oper = src.contains("?") ? "" :"?";
imageUrl = imageUrl =
"$src?imageMogr2/thumbnail/${constraints.constrainWidth() * scaleIndex}" "$src$oper/imageMogr2/thumbnail/${constraints.constrainWidth() * scaleIndex}"
"x${constraints.constrainHeight() * scaleIndex}/format/webp/quality/100"; "x${constraints.constrainHeight() * scaleIndex}/format/webp/quality/100";
} }
// print(imageUrl);
// print("constrainWidth: ${constraints.constrainWidth()}"); // print("constrainWidth: ${constraints.constrainWidth()}");
// print("constrainHeight: ${constraints.constrainHeight()}"); // print("constrainHeight: ${constraints.constrainHeight()}");

Loading…
Cancel
Save