showPhotoViewerDialog function

void showPhotoViewerDialog(
  1. BuildContext context, {
  2. required ImageProvider<Object> imageProvider,
})

显示图片弹窗

imageProvider 图片 (AssetImage(fs.path))

Implementation

void showPhotoViewerDialog(BuildContext context, {required ImageProvider imageProvider}) {
  showDialog<void>(
      useSafeArea: false,
      context: context,
      builder: (BuildContext context) {
        return Dialog(
          insetPadding: EdgeInsets.zero,
          child: Container(
            child: GestureDetector(
              onTapDown: (_) {
                Navigator.pop(context);
              },
              child: PhotoView(
                minScale: PhotoViewComputedScale.contained * 0.5,
                maxScale: PhotoViewComputedScale.contained * 3,
                // tightMode: false,
                imageProvider: imageProvider,
                // heroAttributes: const PhotoViewHeroAttributes(tag: 'someTag'),
                loadingBuilder: (_, __) {
                  return Container(
                    child: Center(
                      child: Theme(
                          data: ThemeData(cupertinoOverrideTheme: CupertinoThemeData(brightness: Brightness.dark)),
                          child: CupertinoActivityIndicator(
                            animating: true,
                          )),
                    ),
                    color: Colors.black,
                  );
                },
                errorBuilder: (context, err, _) {
                  return Container(
                    width: double.infinity,
                    color: Colors.black,
                    child: Center(
                      child: Icon(
                        Icons.broken_image,
                        color: Colors.grey[400],
                        size: 40,
                      ),
                    ),
                  );
                },
              ),
            ),
          ),
        );
      });
}