Skip to content

Commit ccfe79e

Browse files
committed
Implement PhotoView library to enable zoom on gesture
1 parent 84918bf commit ccfe79e

3 files changed

Lines changed: 33 additions & 30 deletions

File tree

lib/src/widgets/building_details/gallery_carousel.dart

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import 'package:flutter/material.dart';
2+
import 'package:photo_view/photo_view.dart';
3+
import 'package:photo_view/photo_view_gallery.dart';
24

35
class 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-
8377
List<Widget> indicators(imagesLength, currentIndex) {
8478
return List<Widget>.generate(imagesLength, (index) {
8579
return Expanded(

pubspec.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,14 @@ packages:
376376
url: "https://pub.dev"
377377
source: hosted
378378
version: "2.1.3"
379+
photo_view:
380+
dependency: "direct main"
381+
description:
382+
name: photo_view
383+
sha256: "8036802a00bae2a78fc197af8a158e3e2f7b500561ed23b4c458107685e645bb"
384+
url: "https://pub.dev"
385+
source: hosted
386+
version: "0.14.0"
379387
platform:
380388
dependency: transitive
381389
description:

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ dependencies:
4242
latlong2: ^0.8.1
4343
flutter_share_me: ^1.4.0
4444
path_provider: ^2.0.11
45+
photo_view: ^0.14.0
4546

4647
dev_dependencies:
4748
flutter_test:

0 commit comments

Comments
 (0)