11import 'package:flutter/material.dart' ;
2+ import 'package:photo_view/photo_view.dart' ;
3+ import 'package:photo_view/photo_view_gallery.dart' ;
24
35class GalleryCarousel extends StatefulWidget {
46 const GalleryCarousel ({Key ? key, required this .galleryImages, required this .imageIndex}) : super (key: key);
@@ -32,26 +34,31 @@ class _GalleryCarouselState extends State<GalleryCarousel> {
3234 padding: const EdgeInsets .fromLTRB (0 , 40 , 0 , 0 ),
3335 child: Row (
3436 children: [
35- IconButton (
36- icon: const Icon (Icons .cancel, color: Colors .white),
37- onPressed: () {Navigator .pop (context);}
38- )],
37+ IconButton (
38+ icon: const Icon (Icons .cancel, color: Colors .white),
39+ onPressed: () {Navigator .pop (context);}
40+ )
41+ ],
3942 )
4043 ),
4144 Expanded (
42- child: PageView .builder (
43- itemCount: widget.galleryImages.length,
44- pageSnapping: true ,
45- controller: _pageController,
46- onPageChanged: (page) {
47- setState (() {
48- _activePage = page;
49- });
50- },
51- itemBuilder: (context, pagePosition) {
52- bool active = pagePosition == _activePage;
53- return slider (widget.galleryImages, pagePosition, active);
54- }
45+ child: PhotoViewGallery .builder (
46+ scrollPhysics: const BouncingScrollPhysics (),
47+ builder: (BuildContext context, int index) {
48+ return PhotoViewGalleryPageOptions (
49+ imageProvider: NetworkImage (widget.galleryImages[index]),
50+ initialScale: PhotoViewComputedScale .contained * 0.9 ,
51+ minScale: PhotoViewComputedScale .contained * 0.8 ,
52+ maxScale: PhotoViewComputedScale .covered * 1.1 ,
53+ );
54+ },
55+ itemCount: widget.galleryImages.length,
56+ pageController: _pageController,
57+ onPageChanged: (page) {
58+ setState (() {
59+ _activePage = page;
60+ });
61+ },
5562 )
5663 ),
5764 Padding (
@@ -67,19 +74,6 @@ class _GalleryCarouselState extends State<GalleryCarousel> {
6774 }
6875}
6976
70- AnimatedContainer slider (images, pagePosition, active) {
71- double margin = active ? 10 : 20 ;
72-
73- return AnimatedContainer (
74- duration: const Duration (milliseconds: 500 ),
75- curve: Curves .easeInOutCubic,
76- margin: EdgeInsets .all (margin),
77- decoration: BoxDecoration (
78- image: DecorationImage (image: NetworkImage (images[pagePosition]))
79- ),
80- );
81- }
82-
8377List <Widget > indicators (imagesLength, currentIndex) {
8478 return List <Widget >.generate (imagesLength, (index) {
8579 return Expanded (
0 commit comments