-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#19: Implement image carousel with fullscreen photo view.
- Loading branch information
Showing
6 changed files
with
163 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:cached_network_image/cached_network_image.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:photo_view/photo_view.dart'; | ||
|
||
class FullScreenImage extends StatelessWidget { | ||
final String imageUrl; | ||
|
||
const FullScreenImage({ | ||
super.key, | ||
required this.imageUrl, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Full Screen Image'), | ||
), | ||
body: PhotoView.customChild( | ||
child: CachedNetworkImage( | ||
imageUrl: imageUrl, | ||
placeholder: (context, url) => const CircularProgressIndicator(), | ||
errorWidget: (context, url, error) => const Icon(Icons.error), | ||
fit: BoxFit.contain, | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import 'package:cached_network_image/cached_network_image.dart'; | ||
import 'package:carousel_slider/carousel_slider.dart'; | ||
import 'package:dots_indicator/dots_indicator.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:iccm_eu_app/components/full_screen_image.dart'; | ||
|
||
class ImageCarousel extends StatefulWidget { | ||
final List<String> imageUrls; | ||
|
||
const ImageCarousel({ | ||
super.key, | ||
required this.imageUrls, | ||
}); | ||
|
||
@override | ||
ImageCarouselState createState() => ImageCarouselState(); | ||
} | ||
|
||
class ImageCarouselState extends State<ImageCarousel> { | ||
int _currentIndex = 0; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (widget.imageUrls.isEmpty) { | ||
return SizedBox.shrink(); | ||
} else { | ||
return Column( | ||
children: [ | ||
CarouselSlider( | ||
options: CarouselOptions( | ||
height: 200, // Adjust height as needed | ||
viewportFraction: 1.0, // Display one image at a time | ||
onPageChanged: (index, reason) { | ||
setState(() { | ||
_currentIndex = index; | ||
}); | ||
}, | ||
), | ||
items: widget.imageUrls.map((imageUrl) { | ||
return Builder( | ||
builder: (BuildContext context) { | ||
return GestureDetector( | ||
onTap: () { | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute( | ||
builder: (context) => FullScreenImage( | ||
imageUrl: imageUrl, | ||
), | ||
), | ||
); | ||
}, | ||
child: Container( | ||
width: MediaQuery | ||
.of(context) | ||
.size | ||
.width, | ||
margin: const EdgeInsets.symmetric(horizontal: 5.0), | ||
decoration: BoxDecoration( | ||
color: Theme.of(context).canvasColor, | ||
), | ||
child: CachedNetworkImage( | ||
imageUrl: imageUrl, | ||
// imageBuilder: (context, imageProvider) => CircleAvatar( | ||
// backgroundImage: imageProvider, | ||
// radius: 50, | ||
// ), | ||
placeholder: (context, url) => const CircularProgressIndicator(), | ||
errorWidget: (context, url, error) => const Icon(Icons.error), | ||
fit: BoxFit.cover, | ||
), | ||
), | ||
); | ||
}, | ||
); | ||
}).toList(), | ||
), | ||
const SizedBox(height: 10), // Spacing between carousel and dots | ||
DotsIndicator( | ||
dotsCount: widget.imageUrls.length, | ||
position: _currentIndex, | ||
decorator: DotsDecorator( | ||
color: Colors.grey, // Inactive dot color | ||
activeColor: Colors.blue, // Active dot color | ||
), | ||
), | ||
], | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters