start static method

dynamic start(
  1. BuildContext context,
  2. List<PumaGuideItem> children,
  3. Function dismissCallback
)

Implementation

static start(BuildContext context, List<PumaGuideItem> children,
    Function dismissCallback) async {
  int count = 0;
  var size = MediaQuery.of(context).size;
  OverlayState? overlayState = Overlay.of(context);
  List<OverlayEntry> entrys = [];
  children.forEach((element) async {
    var offset = _capturePositionWidget(element.globalKey);
    var sizeWidget = _getSizeWidget(element.globalKey);
    entrys.add(
      OverlayEntry(
        builder: (context) {
          final next = () {
            if (element.hapticFeedback) HapticFeedback.mediumImpact();
            if (count == entrys.length - 1) {
              dismissCallback();
            }
            entrys[count].remove();
            count++;
            if (count != entrys.length) {
              overlayState?.insert(entrys[count]);
            }
          };
          final skip = () {
            if (element.hapticFeedback) HapticFeedback.mediumImpact();
            entrys[count].remove();
            dismissCallback();
          };

          List<Widget> content = [
            if (element.builder != null) element.builder!(),
            if (element.builder == null)
              ...defaultBuilder(
                  context,
                  element.title,
                  element.subtitle,
                  element.description,
                  element.titleBackgroundColor,
                  element.textColor),
            if (element.controlAreaBuilder != null)
              element.controlAreaBuilder!(skip: skip, next: next),
            if (element.controlAreaBuilder == null &&
                (element.showSkip || element.showNext))
              defaultControlButtons(
                  context,
                  element.showSkip ? skip : null,
                  element.showNext ? next : null,
                  count,
                  children.length,
                  element.finishWording,
                  element.nextWording,
                  element.skipWording,
                  element.textColor)
          ];

          final screenHeight = MediaQuery.of(context).size.height -
              MediaQuery.of(context).padding.bottom -
              MediaQuery.of(context).padding.top;

          final yOffset =
              offset.dy + sizeWidget.height + element.distanceFromObject;

          final fitBellow = screenHeight - yOffset > element.contentHeight;

          return GestureDetector(
            onTap: next,
            child: Scaffold(
              backgroundColor: Theme.of(context).colorScheme.primaryContainer,
              body: Stack(
                children: [
                  CustomPaint(
                    size: size,
                    painter: HolePainter(
                        shapeFocus: element.shapeFocus,
                        dx: offset.dx + (sizeWidget.width / 2),
                        dy: offset.dy + (sizeWidget.height / 2),
                        width: sizeWidget.width,
                        overlayBackgroundColor:
                            element.overlayBackgroundColor,
                        height: sizeWidget.height),
                  ),
                  CustomPaint(
                    size: size,
                    painter: ArrowPainter(
                        context: context,
                        distanceFromObject: element.distanceFromObject,
                        dx: offset.dx + (sizeWidget.width / 2),
                        dy: offset.dy + (sizeWidget.height / 2),
                        arrowBuilder: element.arrowBuilder,
                        contentHeight: element.contentHeight,
                        contentWidth: element.contentWidth,
                        width: sizeWidget.width,
                        height: sizeWidget.height,
                        fitBellow: fitBellow,
                        color: element.titleBackgroundColor ??
                            Theme.of(context).primaryColor),
                  ),
                  Positioned(
                    top: fitBellow ? yOffset : null,
                    bottom: !fitBellow
                        ? MediaQuery.of(context).size.height -
                            offset.dy +
                            element.distanceFromObject
                        : null,
                    left: 0,
                    right: 0,
                    child: Center(
                      child: Container(
                        color: element.debugShowContentContainer
                            ? Theme.of(context).colorScheme.error
                            : null,
                        width: element.contentWidth,
                        height: element.contentHeight,
                        child: Column(
                          mainAxisAlignment: fitBellow
                              ? MainAxisAlignment.start
                              : MainAxisAlignment.end,
                          mainAxisSize: MainAxisSize.min,
                          children: element.invertContentOrder ||
                                  (element.invertContentIfNotFitBellow &&
                                      !fitBellow)
                              ? content.reversed.toList()
                              : content,
                        ),
                      ),
                    ),
                  )
                ],
              ),
            ),
          );
        },
      ),
    );
  });

  overlayState?.insert(entrys[0]);
}