buildCarousel method
Build the image carousel.
Implementation
Widget buildCarousel({
required int itemCount,
required AppModel appModel,
}) {
return ChangeNotifierBuilder(
notifier: carouselNotifier,
builder: (_, __, ___) {
return CarouselSlider.builder(
key: carouselKey,
itemCount: itemCount + 1,
options: CarouselOptions(
enlargeStrategy: CenterPageEnlargeStrategy.zoom,
enlargeCenterPage: true,
viewportFraction: 0.75,
initialPage: indexNotifier.value,
onPageChanged: (index, reason) {
if (index == itemCount) {
indexNotifier.value = -1;
setSelectedSearchSuggestion(index: -1);
} else {
indexNotifier.value = index;
setSelectedSearchSuggestion(index: index);
}
},
),
itemBuilder: (context, index, realIndex) {
if (index == itemCount) {
return Container(
color: appModel.isDarkMode ? Colors.white10 : Colors.black12,
);
}
OverlayEntry? popup;
ImageProvider<Object> image = currentImageSuggestions![index];
return GestureDetector(
onLongPress: () {
if (index != indexNotifier.value) {
return;
}
popup = OverlayEntry(
builder: (context) => ColoredBox(
color: Colors.black.withOpacity(0.5),
child: buildImage(image: image, fit: BoxFit.contain),
),
);
Overlay.of(context).insert(popup!);
},
onLongPressEnd: (details) {
popup?.remove();
},
child: Padding(
padding: Spacing.of(context).insets.horizontal.small,
child: buildImage(
image: currentImageSuggestions![index],
fit: BoxFit.fitHeight,
),
),
);
},
);
},
);
}