mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
mod: reply pic showing
This commit is contained in:
61
lib/common/widgets/imageview.dart
Normal file
61
lib/common/widgets/imageview.dart
Normal file
@@ -0,0 +1,61 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:PiliPalaX/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPalaX/common/widgets/nine_grid_view.dart';
|
||||
import 'package:PiliPalaX/pages/preview/view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Widget image(
|
||||
double maxWidth,
|
||||
List<dynamic> picArr,
|
||||
) {
|
||||
double imageWidth = (maxWidth - 2 * 5) / 3;
|
||||
double imageHeight = imageWidth;
|
||||
if (picArr.length == 1) {
|
||||
dynamic width = picArr[0]['img_width'];
|
||||
dynamic height = picArr[0]['img_height'];
|
||||
double ratioWH = width / height;
|
||||
double ratioHW = height / width;
|
||||
double maxRatio = 22 / 9;
|
||||
imageWidth = ratioWH > 1.5
|
||||
? maxWidth
|
||||
: (ratioWH >= 1 || (height > width && ratioHW < 1.5))
|
||||
? 2 * imageWidth
|
||||
: imageWidth;
|
||||
imageHeight = imageWidth * min(ratioHW, maxRatio);
|
||||
}
|
||||
return NineGridView(
|
||||
type: NineGridType.weiBo,
|
||||
margin: const EdgeInsets.only(top: 6),
|
||||
bigImageWidth: imageWidth,
|
||||
bigImageHeight: imageHeight,
|
||||
space: 5,
|
||||
height: picArr.length == 1 ? imageHeight : null,
|
||||
width: picArr.length == 1 ? imageWidth : maxWidth,
|
||||
itemCount: picArr.length,
|
||||
itemBuilder: (context, index) => GestureDetector(
|
||||
onTap: () {
|
||||
showDialog(
|
||||
useSafeArea: false,
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return ImagePreview(
|
||||
initialPage: index,
|
||||
imgList: picArr.map((item) => item['img_src'] as String).toList(),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: NetworkImgLayer(
|
||||
src: picArr[index]['img_src'],
|
||||
width: imageWidth,
|
||||
height: imageWidth,
|
||||
origAspectRatio:
|
||||
picArr[index]['img_width'] / picArr[index]['img_height'],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user