1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- /*
- * @Author: XianKaiQun
- * @LastEditors : WuWei
- * @Date: 2020-11-04 14:32:20
- * @LastEditTime : 2022-01-19 10:47:18
- */
- import 'package:flutter/material.dart';
- import 'package:wisdom_cli/wisdom_cli.dart';
- ///[WImagePreview]嵌入式图片预览widget,
- ///提供`onDelete`事件,则右上角关闭小圈圈就会显示,不提供则不显示
- class WImagePreview extends StatelessWidget {
- const WImagePreview({
- Key? key,
- required this.images,
- required this.index,
- required this.onDelete,
- this.size,
- }) : super(key: key);
- final List<ImageProvider> images;
- final double? size;
- final int index;
- final void Function()? onDelete;
- ///一般来说,使用[WImagePreview]嵌入式图片预览widget时,没有意外的话都会直接构造一个列表,
- ///所以这里提供一个快速构建一个`List<Widget>`的方法,
- ///这样你可以使[WImagePreview]和
- static List<WImagePreview> buildList({
- List<ImageProvider>? images,
- void Function(int index)? onDelete,
- double? size,
- }) {
- return [
- if (images != null && images.length > 0)
- for (int i = 0; i < images.length; i++)
- WImagePreview(
- size: size,
- images: images,
- index: i,
- onDelete: onDelete == null ? null : () => onDelete(i),
- )
- ];
- }
- @override
- Widget build(BuildContext context) {
- return Wisdom.stack(
- width: size ?? 65.pt,
- height: size ?? 65.pt,
- clipBehavior: Clip.none,
- children: [
- Wisdom(
- onTap: () => WisPhotoViewUtil.show(images, index),
- padding: EdgeInsets.only(right: 5.pt, top: 5.pt),
- child: DecoratedBox(
- position: DecorationPosition.foreground,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(4.pt),
- border: Border.all(color: Colors.black12, width: 0.5.pt),
- ),
- child: WImage(
- image: images[index],
- borderRadius: BorderRadius.circular(4.pt),
- width: size ?? 65.pt,
- height: size ?? 65.pt,
- fit: BoxFit.cover,
- ),
- ),
- ),
- if (onDelete != null)
- Positioned(
- right: 0,
- top: 0,
- child: WClose(
- onTap: onDelete,
- backgroundColor: Colors.black.withOpacity(0.6),
- color: Colors.white,
- ),
- ),
- ],
- );
- }
- }
|