Skip to content

Commit

Permalink
feat: carousel photos
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasz-trela committed Jan 17, 2025
1 parent c9500a2 commit 86abf72
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import "dart:async";

import "package:carousel_slider_plus/carousel_slider_plus.dart";
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:flutter/material.dart";

import "../../../../config/ui_config.dart";
import "digital_guide_image.dart";

class DigitalGuideCarouselWithIndicator extends StatefulWidget {
const DigitalGuideCarouselWithIndicator({super.key, required this.imgListId});

final IList<int> imgListId;

@override
State<StatefulWidget> createState() {
return _CarouselWithIndicatorState();
}
}

class _CarouselWithIndicatorState
extends State<DigitalGuideCarouselWithIndicator> {
int _current = 0;
final CarouselSliderController _controller = CarouselSliderController();

@override
Widget build(BuildContext context) {
return Dialog(
insetPadding: EdgeInsets.zero,
backgroundColor: Colors.transparent,
child: Wrap(
children: [
CarouselSlider(
items: widget.imgListId
.map(
(item) => ClipRRect(
borderRadius: const BorderRadius.all(
Radius.circular(DigitalGuideConfig.borderRadiusMedium),),
child: DigitalGuideImage(id: item),
),
)
.toList(),
controller: _controller,
options: CarouselOptions(
autoPlay: true,
enlargeCenterPage: true,
onPageChanged: (index, reason) {
setState(() => _current = index);
},
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: widget.imgListId.asMap().entries.map((entry) {
return GestureDetector(
onTap: () => unawaited(_controller.animateToPage(entry.key)),
child: Container(
width: 12,
height: 12,
margin: const EdgeInsets.symmetric(
vertical: DigitalGuideConfig.heightMedium,
horizontal: 4,
),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.black
.withAlpha(_current == entry.key ? 230 : 102),
),
),
);
}).toList(),
),
],
),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import "dart:async";

import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:flutter/material.dart";

import "../../../../config/ui_config.dart";
import "../../../../utils/context_extensions.dart";
import "digital_guide_carousel.dart";
import "digital_guide_image.dart";
import "digital_guide_nav_link.dart";

Expand Down Expand Up @@ -49,11 +52,20 @@ class DigitalGuidePhotoRow extends StatelessWidget {
top: DigitalGuideConfig.heightSmall,
),
child: DigitalGuideNavLink(
onTap: () => {},
onTap: () async => showGallery(context),
text: context.localize.see_all_photos(imagesIDs.length),
),
),
],
);
}

Future<void> showGallery(BuildContext context) async {
await showDialog(
context: context,
builder: (context) => DigitalGuideCarouselWithIndicator(
imgListId: imagesIDs,
),
);
}
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ dependencies:
animated_list_plus: ^0.5.2
dotted_border: ^2.1.0
fluttertoast: ^8.2.8
carousel_slider_plus: ^7.1.0

#Data
freezed_annotation: ^2.4.4
Expand Down

0 comments on commit 86abf72

Please sign in to comment.