-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(digital-guide): add photos gallery (#535)
* feat: carousel photos * chore: format code * refactor: replace statefull widget with flutter hooks and ui adjustments
- Loading branch information
1 parent
8075640
commit a8e4fbb
Showing
3 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
lib/features/digital_guide_view/presentation/widgets/digital_guide_carousel.dart
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,82 @@ | ||
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 "package:flutter_hooks/flutter_hooks.dart"; | ||
|
||
import "../../../../config/ui_config.dart"; | ||
import "digital_guide_image.dart"; | ||
|
||
class DigitalGuideCarouselWithIndicator extends HookWidget { | ||
const DigitalGuideCarouselWithIndicator({ | ||
super.key, | ||
required this.imgListId, | ||
this.initId, | ||
}); | ||
|
||
final IList<int> imgListId; | ||
final int? initId; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final current = useState( | ||
initId != null ? imgListId.indexOf(initId!) : 0, | ||
); | ||
final controller = useMemoized(CarouselSliderController.new); | ||
|
||
return Dialog( | ||
insetPadding: EdgeInsets.zero, | ||
backgroundColor: Colors.transparent, | ||
child: Wrap( | ||
children: [ | ||
CarouselSlider( | ||
items: imgListId | ||
.map( | ||
(item) => ClipRRect( | ||
borderRadius: const BorderRadius.all( | ||
Radius.circular(DigitalGuideConfig.borderRadiusMedium), | ||
), | ||
child: DigitalGuideImage( | ||
id: item, | ||
zoomable: false, | ||
), | ||
), | ||
) | ||
.toList(), | ||
controller: controller, | ||
options: CarouselOptions( | ||
initialPage: current.value, | ||
autoPlay: true, | ||
enlargeCenterPage: true, | ||
onPageChanged: (index, reason) { | ||
current.value = index; | ||
}, | ||
), | ||
), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: 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.value == entry.key ? 230 : 102), | ||
), | ||
), | ||
); | ||
}).toList(), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
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