build method
Widget
build(
- BuildContext context,
- BubbleShowcase bubbleShowcase,
- int currentSlideIndex,
- void goToSlide(),
Builds the whole slide widget.
Implementation
Widget build(
BuildContext context,
BubbleShowcase bubbleShowcase,
int currentSlideIndex,
void Function(int) goToSlide,
) {
Position highlightPosition = getHighlightPosition(
context,
bubbleShowcase,
currentSlideIndex,
);
List<Widget> children;
switch (passthroughMode) {
case PassthroughMode.NONE:
children = [
Positioned.fill(
child: CustomPaint(
painter: OverlayPainter(this, highlightPosition),
),
),
];
break;
case PassthroughMode.INSIDE_WITH_NOTIFICATION:
children = [
Positioned.fill(
child: ClipPath(
clipper: OverlayClipper(this, highlightPosition),
child: Container(
color: Colors.black54,
),
),
),
];
break;
}
// Add BubbleSlide
if (child?.widget != null) {
children.add(
child!.build(
context,
highlightPosition,
MediaQuery.of(context).size,
),
);
}
// Add counter text
int slidesCount = bubbleShowcase.bubbleSlides.length;
Color writeColor =
Utils.isColorDark(boxShadow.color) ? Colors.white : Colors.black;
if (bubbleShowcase.counterText != null) {
children.add(
Positioned(
bottom: 5,
left: 0,
right: 0,
child: Text(
bubbleShowcase.counterText!
.replaceAll(':i', (currentSlideIndex + 1).toString())
.replaceAll(':n', slidesCount.toString()),
style: Theme.of(context)
.textTheme
.bodyText2!
.copyWith(color: writeColor),
textAlign: TextAlign.center,
),
),
);
}
// Add Close button
if (bubbleShowcase.showCloseButton) {
children.add(Positioned(
top: MediaQuery.of(context).padding.top,
left: 0,
child: GestureDetector(
onTap: () => goToSlide(slidesCount),
child: Icon(
Icons.close,
color: writeColor,
),
),
));
}
if (passthroughMode == PassthroughMode.INSIDE_WITH_NOTIFICATION) {
return Stack(
children: children,
);
} else {
return GestureDetector(
onTap: () => goToSlide(currentSlideIndex + 1),
child: Stack(
children: children,
),
);
}
}