|
@@ -1,5 +1,6 @@ |
|
|
import 'dart:io'; |
|
|
import 'dart:io'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
|
import 'package:loading_indicator/loading_indicator.dart'; |
|
|
|
|
|
|
|
|
import 'package:photo_view/photo_view.dart'; |
|
|
import 'package:photo_view/photo_view.dart'; |
|
|
import 'package:photo_view/photo_view_gallery.dart'; |
|
|
import 'package:photo_view/photo_view_gallery.dart'; |
|
@@ -9,16 +10,25 @@ import 'package:zhiying_comm/zhiying_comm.dart'; |
|
|
class PhotoPreview extends StatefulWidget { |
|
|
class PhotoPreview extends StatefulWidget { |
|
|
List<PreviewImageData> previewImageDatas; |
|
|
List<PreviewImageData> previewImageDatas; |
|
|
int index; |
|
|
int index; |
|
|
|
|
|
String heroTagSuffix; |
|
|
|
|
|
|
|
|
PhotoPreview({Key key, this.previewImageDatas, this.index = 0}) |
|
|
|
|
|
|
|
|
PhotoPreview( |
|
|
|
|
|
{Key key, |
|
|
|
|
|
this.previewImageDatas, |
|
|
|
|
|
this.index = 0, |
|
|
|
|
|
this.heroTagSuffix = ""}) |
|
|
: super(key: key); |
|
|
: super(key: key); |
|
|
|
|
|
|
|
|
PhotoPreview._showPhotoViewByData( |
|
|
PhotoPreview._showPhotoViewByData( |
|
|
{Key key, this.previewImageDatas, this.index}) |
|
|
|
|
|
: super(key: key); |
|
|
|
|
|
|
|
|
{Key key, |
|
|
|
|
|
this.previewImageDatas, |
|
|
|
|
|
this.index = 0, |
|
|
|
|
|
this.heroTagSuffix = ""}) |
|
|
|
|
|
: super(key: key) { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
PhotoPreview._showPhotoViewByImages( |
|
|
PhotoPreview._showPhotoViewByImages( |
|
|
{Key key, List<String> images, this.index}) |
|
|
|
|
|
|
|
|
{Key key, List<String> images, this.index = 0, this.heroTagSuffix = ""}) |
|
|
: super(key: key) { |
|
|
: super(key: key) { |
|
|
if (images != null) { |
|
|
if (images != null) { |
|
|
previewImageDatas = List(); |
|
|
previewImageDatas = List(); |
|
@@ -32,21 +42,23 @@ class PhotoPreview extends StatefulWidget { |
|
|
///显示类型的一些预览 |
|
|
///显示类型的一些预览 |
|
|
static showPhotoPreview( |
|
|
static showPhotoPreview( |
|
|
BuildContext context, List<PreviewImageData> previewImageDatas, |
|
|
BuildContext context, List<PreviewImageData> previewImageDatas, |
|
|
{int currentIndex = 0}) { |
|
|
|
|
|
|
|
|
{int currentIndex = 0, String heroTagSuffix}) { |
|
|
Navigator.of(context).push(new FadeRoute( |
|
|
Navigator.of(context).push(new FadeRoute( |
|
|
page: PhotoPreview._showPhotoViewByData( |
|
|
page: PhotoPreview._showPhotoViewByData( |
|
|
previewImageDatas: previewImageDatas, |
|
|
previewImageDatas: previewImageDatas, |
|
|
index: currentIndex, |
|
|
index: currentIndex, |
|
|
|
|
|
heroTagSuffix: heroTagSuffix, |
|
|
))); |
|
|
))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
///显示仅仅是一组list<String>类型的图片预览 |
|
|
///显示仅仅是一组list<String>类型的图片预览 |
|
|
static showPhotoPreviewByimages(BuildContext context, List<String> images, |
|
|
static showPhotoPreviewByimages(BuildContext context, List<String> images, |
|
|
{int currentIndex = 0}) { |
|
|
|
|
|
|
|
|
{int currentIndex = 0, String heroTagSuffix = ""}) { |
|
|
Navigator.of(context).push(new FadeRoute( |
|
|
Navigator.of(context).push(new FadeRoute( |
|
|
page: PhotoPreview._showPhotoViewByImages( |
|
|
page: PhotoPreview._showPhotoViewByImages( |
|
|
images: images, |
|
|
images: images, |
|
|
index: currentIndex, |
|
|
index: currentIndex, |
|
|
|
|
|
heroTagSuffix: heroTagSuffix, |
|
|
))); |
|
|
))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -71,7 +83,7 @@ class _PhotoPreviewState extends State<PhotoPreview> { |
|
|
images: widget.previewImageDatas, |
|
|
images: widget.previewImageDatas, |
|
|
index: widget.index, |
|
|
index: widget.index, |
|
|
controller: pageController, |
|
|
controller: pageController, |
|
|
heroTag: "", |
|
|
|
|
|
|
|
|
heroTagSuffix: widget.heroTagSuffix ?? "", |
|
|
)); |
|
|
)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@@ -100,7 +112,7 @@ enum PreviewImageType { |
|
|
class PhotoViewGalleryScreen extends StatefulWidget { |
|
|
class PhotoViewGalleryScreen extends StatefulWidget { |
|
|
List<PreviewImageData> images = []; |
|
|
List<PreviewImageData> images = []; |
|
|
int index = 0; |
|
|
int index = 0; |
|
|
String heroTag; |
|
|
|
|
|
|
|
|
String heroTagSuffix; |
|
|
PageController controller; |
|
|
PageController controller; |
|
|
|
|
|
|
|
|
PhotoViewGalleryScreen( |
|
|
PhotoViewGalleryScreen( |
|
@@ -108,7 +120,7 @@ class PhotoViewGalleryScreen extends StatefulWidget { |
|
|
@required this.images, |
|
|
@required this.images, |
|
|
this.index, |
|
|
this.index, |
|
|
this.controller, |
|
|
this.controller, |
|
|
this.heroTag}) |
|
|
|
|
|
|
|
|
this.heroTagSuffix}) |
|
|
: super(key: key) { |
|
|
: super(key: key) { |
|
|
controller = PageController(initialPage: index); |
|
|
controller = PageController(initialPage: index); |
|
|
} |
|
|
} |
|
@@ -143,8 +155,10 @@ class _PhotoViewGalleryScreenState extends State<PhotoViewGalleryScreen> { |
|
|
builder: (BuildContext context, int index) { |
|
|
builder: (BuildContext context, int index) { |
|
|
return PhotoViewGalleryPageOptions( |
|
|
return PhotoViewGalleryPageOptions( |
|
|
imageProvider: _buildPage(context, index), |
|
|
imageProvider: _buildPage(context, index), |
|
|
heroAttributes: widget.heroTag.isNotEmpty |
|
|
|
|
|
? PhotoViewHeroAttributes(tag: widget.heroTag) |
|
|
|
|
|
|
|
|
heroAttributes: widget.heroTagSuffix.isNotEmpty |
|
|
|
|
|
? PhotoViewHeroAttributes( |
|
|
|
|
|
tag: (widget.images[index].data ?? "") + |
|
|
|
|
|
widget.heroTagSuffix) |
|
|
: null, |
|
|
: null, |
|
|
); |
|
|
); |
|
|
}, |
|
|
}, |
|
@@ -152,6 +166,19 @@ class _PhotoViewGalleryScreenState extends State<PhotoViewGalleryScreen> { |
|
|
loadFailedChild: Container( |
|
|
loadFailedChild: Container( |
|
|
child: Text("加载失败"), |
|
|
child: Text("加载失败"), |
|
|
), |
|
|
), |
|
|
|
|
|
loadingBuilder: (context,event){ |
|
|
|
|
|
return Column( |
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
|
|
children: <Widget>[ |
|
|
|
|
|
Container( |
|
|
|
|
|
width: 48, |
|
|
|
|
|
constraints: BoxConstraints(maxWidth: 48,maxHeight: 48), |
|
|
|
|
|
height: 48, |
|
|
|
|
|
child: LoadingIndicator(indicatorType: Indicator.ballSpinFadeLoader,color: Colors.white,) |
|
|
|
|
|
), |
|
|
|
|
|
], |
|
|
|
|
|
); |
|
|
|
|
|
}, |
|
|
backgroundDecoration: BoxDecoration(color: Colors.black), |
|
|
backgroundDecoration: BoxDecoration(color: Colors.black), |
|
|
pageController: widget.controller, |
|
|
pageController: widget.controller, |
|
|
enableRotation: true, |
|
|
enableRotation: true, |
|
@@ -220,12 +247,9 @@ class FadeRoute extends PageRouteBuilder { |
|
|
Animation<double> secondaryAnimation, |
|
|
Animation<double> secondaryAnimation, |
|
|
Widget child, |
|
|
Widget child, |
|
|
) => |
|
|
) => |
|
|
ScaleTransition( |
|
|
|
|
|
scale: animation, |
|
|
|
|
|
child: FadeTransition( |
|
|
|
|
|
opacity: animation, |
|
|
|
|
|
child: child, |
|
|
|
|
|
), |
|
|
|
|
|
|
|
|
FadeTransition( |
|
|
|
|
|
opacity: animation, |
|
|
|
|
|
child: child, |
|
|
), |
|
|
), |
|
|
); |
|
|
); |
|
|
} |
|
|
} |