Browse Source

图片优化更改

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

97
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<CommunityDynamic> {
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<CommunityDynamic> {
}
////
_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,13 +171,20 @@ class _CommunityDynamic extends State<CommunityDynamic> {
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
), ));
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(
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,
@ -224,7 +229,8 @@ class _CommunityDynamic extends State<CommunityDynamic> {
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<CommunityDynamic> {
size: 15,
),
))
: Padding(padding: EdgeInsets.all(20),child:Icon(
: Padding(
padding: EdgeInsets.all(20),
child: Icon(
Icons.close,
color: Colors.black,
size: 16,
),),
),
),
),
],
),
@ -340,23 +349,30 @@ class _CommunityDynamic extends State<CommunityDynamic> {
}
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
), ), );
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,
cnt["images"][0].replaceAll(".jpg", ".jpg?imageView2/0/q/75"),
fit: BoxFit.contain,
radius: BorderRadius.circular(2),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.width,
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",
)),
@ -364,8 +380,8 @@ class _CommunityDynamic extends State<CommunityDynamic> {
} else {
itemWidget = GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: (cnt["images"].length == 2 ||
cnt["images"].length == 4)
crossAxisCount:
(cnt["images"].length == 2 || cnt["images"].length == 4)
? 2
: 3,
crossAxisSpacing: 12.w,
@ -380,13 +396,19 @@ class _CommunityDynamic extends State<CommunityDynamic> {
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<CommunityDynamic> {
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<CommunityDynamic> {
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: [

5
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()}");

Loading…
Cancel
Save