diff --git a/lib/community/community_view/community_dynamic.dart b/lib/community/community_view/community_dynamic.dart index c9e4bc24..556654a0 100644 --- a/lib/community/community_view/community_dynamic.dart +++ b/lib/community/community_view/community_dynamic.dart @@ -17,6 +17,9 @@ import 'package:image_pickers/image_pickers.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:video_player/video_player.dart'; +import '../photo_view_gallery_screen.dart'; + + class CommunityDynamic extends StatefulWidget { final int itemCount; final Function(double height) heightFun; @@ -166,14 +169,19 @@ class _CommunityDynamic extends State { height: 44, child: Row( children: [ - MImage( - widget?.comment?.memberInfo?.avatar ?? "", - width: 44, - height: 44, - isCircle: true, - fit: BoxFit.cover, - errorSrc: "assets/image/default_1.png", - fadeSrc: "assets/image/default_1.png", + GestureDetector( + onTap: (){ + // ImagePickers.previewImages(widget.comment.memberInfo.avatar); + }, + child: MImage( + widget?.comment?.memberInfo?.avatar ?? "", + width: 44, + height: 44, + isCircle: true, + fit: BoxFit.cover, + errorSrc: "assets/image/default_1.png", + fadeSrc: "assets/image/default_1.png", + ), ), SizedBox( width: 8, @@ -360,7 +368,11 @@ class _CommunityDynamic extends State { return Container( child: InkWell( onTap: () { - ImagePickers.previewImages(subjectInfo.images, position); + // ImagePickers.previewImages(subjectInfo.images, position); + Navigator.push(context, MaterialPageRoute( builder: (context) => PhotoViewGalleryScreen( + images:subjectInfo.images,//传入图片list + index: position,//传入当前点击的图片的index + ), ), ); }, child: MImage( subjectInfo.images[position], diff --git a/lib/community/photo_view_gallery_screen.dart b/lib/community/photo_view_gallery_screen.dart new file mode 100644 index 00000000..08c0e0f7 --- /dev/null +++ b/lib/community/photo_view_gallery_screen.dart @@ -0,0 +1,93 @@ +import 'package:flutter/material.dart'; +import 'package:photo_view/photo_view.dart'; +import 'package:photo_view/photo_view_gallery.dart'; + +class PhotoViewGalleryScreen extends StatefulWidget { + List images=[]; + int index=0; + String heroTag; + PageController controller; + + PhotoViewGalleryScreen({Key key,@required this.images,this.index,this.controller,this.heroTag}) : super(key: key){ + controller=PageController(initialPage: index); + } + + @override + _PhotoViewGalleryScreenState createState() => _PhotoViewGalleryScreenState(); +} + +class _PhotoViewGalleryScreenState extends State { + int currentIndex=0; + + @override + void initState() { + // TODO: implement initState + super.initState(); + currentIndex=widget.index; + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Stack( + children: [ + Positioned( + top: 0, + left: 0, + bottom: 0, + right: 0, + child: Container( + child: PhotoViewGallery.builder( + scrollPhysics: const BouncingScrollPhysics(), + builder: (BuildContext context, int index) { + return PhotoViewGalleryPageOptions( + imageProvider: NetworkImage(widget.images[index]), + + ); + }, + itemCount: widget.images.length, + loadingBuilder: (context, progress) => Center( + child: Container( + width: 20.0, + height: 20.0, + child: CircularProgressIndicator( + value: progress == null + ? null + : progress.cumulativeBytesLoaded / + progress.expectedTotalBytes, + ), + ), + ), + backgroundDecoration: null, + pageController: widget.controller, + enableRotation: true, + onPageChanged: (index){ + setState(() { + currentIndex=index; + }); + }, + ) + ), + ), + Positioned(//图片index显示 + top: MediaQuery.of(context).padding.top+15, + width: MediaQuery.of(context).size.width, + child: Center( + child: Text("${currentIndex+1}/${widget.images.length}",style: TextStyle(color: Colors.white,fontSize: 16)), + ), + ), + Positioned(//右上角关闭按钮 + right: 10, + top: MediaQuery.of(context).padding.top, + child: IconButton( + icon: Icon(Icons.close,size: 30,color: Colors.white,), + onPressed: (){ + Navigator.of(context).pop(); + }, + ), + ), + ], + ), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index 72f074a7..4d59a3ca 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -70,6 +70,7 @@ import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'; import 'community/community_view/class_details.dart'; import 'community/headlines/headlines_column_details.dart'; +import 'community/photo_view_gallery_screen.dart'; import 'home/guide_page.dart'; import 'home/home_view/activity_list.dart'; import 'main_page.dart'; @@ -325,4 +326,6 @@ Map routers = { MineAttainmentPage(arguments: arguments), '/router/headlines_column_details': (context, {arguments}) => HeadlinesColumnDetails(arguments: arguments), + '/router/photo_view_gallery_screen': (context, {arguments}) => + PhotoViewGalleryScreen(), }; diff --git a/pubspec.lock b/pubspec.lock index 8bac3749..189e0f23 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -524,7 +524,7 @@ packages: name: photo_view url: "https://pub.flutter-io.cn" source: hosted - version: "0.11.1" + version: "0.13.0" platform: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index b82c67f6..6a5c371b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -68,7 +68,7 @@ dependencies: flutter_html: ^2.1.5 #2.1.0 chewie_audio: ^1.1.2 - photo_view: ^0.11.1 + photo_view: ^0.13.0 video_player: ^2.2.3 thumbnails: ^1.0.1 # media_info: ^0.9.0