feat:更新组件UI
This commit is contained in:
@@ -75,7 +75,7 @@ class _ImagePreviewPageState extends State<ImagePreviewPage> {
|
||||
pageOptions:
|
||||
widget.images.map((url) {
|
||||
return PhotoViewGalleryPageOptions(
|
||||
imageProvider: NetworkImage(url),
|
||||
imageProvider: NetworkImage('${AppConfig.imageBaseUrl}$url'),
|
||||
minScale: PhotoViewComputedScale.contained,
|
||||
maxScale: PhotoViewComputedScale.covered * 2,
|
||||
// 点击空白处关闭预览
|
||||
@@ -91,42 +91,27 @@ class _ImagePreviewPageState extends State<ImagePreviewPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Widget buildFileImage(BuildContext context, File imageFile) {
|
||||
return GestureDetector(
|
||||
onTap: () => showFullScreenImage(context, FileImage(imageFile)),
|
||||
child: Image(
|
||||
image: FileImage(imageFile),
|
||||
width: 120,
|
||||
height: 120,
|
||||
fit: BoxFit.cover,
|
||||
loadingBuilder: (context, child, loadingProgress) {
|
||||
if (loadingProgress == null) return child;
|
||||
return buildImageLoadingIndicator(loadingProgress);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildNetworkImage(BuildContext context, String url) {
|
||||
Widget buildNetworkImage(
|
||||
BuildContext context,
|
||||
List<String> imageUrls,
|
||||
int index,
|
||||
) {
|
||||
return AspectRatio(
|
||||
aspectRatio: 1.5,
|
||||
aspectRatio: 4 / 3,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
showFullScreenImage(
|
||||
context,
|
||||
NetworkImage('${AppConfig.imageBaseUrl}$url'),
|
||||
);
|
||||
showFullScreenImage(context, imageUrls, index);
|
||||
},
|
||||
child: Image.network(
|
||||
'${AppConfig.imageBaseUrl}$url',
|
||||
'${AppConfig.imageBaseUrl}${imageUrls[index]}',
|
||||
fit: BoxFit.cover,
|
||||
loadingBuilder: (context, child, loadingProgress) {
|
||||
if (loadingProgress == null) return child;
|
||||
return buildImageLoadingIndicator(loadingProgress);
|
||||
},
|
||||
errorBuilder: (context, error, stackTrace) => _buildErrorImage(),
|
||||
errorBuilder: (context, error, stackTrace) => buildErrorImage(),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -135,7 +120,8 @@ Widget buildNetworkImage(BuildContext context, String url) {
|
||||
|
||||
Widget buildImagePreviewItem({
|
||||
required BuildContext context,
|
||||
required String imageUrl,
|
||||
required List<String> imageUrls,
|
||||
required int index,
|
||||
required VoidCallback onRemoveImage,
|
||||
}) {
|
||||
return Container(
|
||||
@@ -144,7 +130,7 @@ Widget buildImagePreviewItem({
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Stack(
|
||||
children: [
|
||||
buildNetworkImage(context, imageUrl),
|
||||
buildNetworkImage(context, imageUrls, index),
|
||||
buildDeleteImage(onRemoveImage: onRemoveImage),
|
||||
],
|
||||
),
|
||||
@@ -168,7 +154,7 @@ Widget buildImageLoadingIndicator(ImageChunkEvent? loadingProgress) {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildErrorImage() {
|
||||
Widget buildErrorImage() {
|
||||
return Container(
|
||||
color: Colors.grey[200],
|
||||
child: const Icon(Icons.image, color: Colors.grey, size: 30),
|
||||
@@ -183,7 +169,7 @@ Widget _buildPhotoView(ImageProvider imageProvider) {
|
||||
maxScale: PhotoViewComputedScale.covered * 2,
|
||||
initialScale: PhotoViewComputedScale.contained,
|
||||
loadingBuilder: (context, event) => buildImageLoadingIndicator(event),
|
||||
errorBuilder: (context, error, stackTrace) => _buildErrorImage(),
|
||||
errorBuilder: (context, error, stackTrace) => buildErrorImage(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -198,29 +184,40 @@ Widget _buildCloseImage(BuildContext context) {
|
||||
);
|
||||
}
|
||||
|
||||
void showFullScreenImage(BuildContext context, ImageProvider imageProvider) {
|
||||
Navigator.of(context).push(
|
||||
PageRouteBuilder(
|
||||
opaque: false,
|
||||
pageBuilder: (
|
||||
BuildContext context,
|
||||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black.withAlpha(200),
|
||||
body: Stack(
|
||||
children: [
|
||||
// 可缩放图片
|
||||
Positioned.fill(child: _buildPhotoView(imageProvider)),
|
||||
// 关闭按钮
|
||||
_buildCloseImage(context),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
void showFullScreenImage(
|
||||
BuildContext context,
|
||||
List<String> imageUrls,
|
||||
int index,
|
||||
) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder:
|
||||
(context) => ImagePreviewPage(images: imageUrls, initialIndex: index),
|
||||
),
|
||||
);
|
||||
// Navigator.of(context).push(
|
||||
// PageRouteBuilder(
|
||||
// opaque: false,
|
||||
// pageBuilder: (
|
||||
// BuildContext context,
|
||||
// Animation<double> animation,
|
||||
// Animation<double> secondaryAnimation,
|
||||
// ) {
|
||||
// return Scaffold(
|
||||
// backgroundColor: Colors.black.withAlpha(200),
|
||||
// body: Stack(
|
||||
// children: [
|
||||
// // 可缩放图片
|
||||
// Positioned.fill(child: _buildPhotoView(imageProvider)),
|
||||
// // 关闭按钮
|
||||
// _buildCloseImage(context),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
}
|
||||
|
||||
Widget buildImageUploadButton({required VoidCallback onPickImage}) {
|
||||
|
||||
Reference in New Issue
Block a user