openPage<T> method

Future<T?> openPage<T>(
  1. Widget page, {
  2. Duration duration = const Duration(milliseconds: 300),
})

Open a new page on top of the current page.

This method navigates to a new page using a fade transition animation.

Implementation

Future<T?> openPage<T>(
  Widget page, {
  Duration duration = const Duration(milliseconds: 300),
}) {
  layerInteractionManager.selectedLayerId = '';
  _checkInteractiveViewer();
  isSubEditorOpen = true;

  if (paintEditorConfigs.freeStyleHighPerformanceHero) {
    layerInteractionManager.freeStyleHighPerformanceHero = true;
  }

  setState(() {});

  SubEditor editorName = SubEditor.unknown;

  if (T is PaintingEditor) {
    editorName = SubEditor.paint;
  } else if (T is TextEditor) {
    editorName = SubEditor.text;
  } else if (T is CropRotateEditor) {
    editorName = SubEditor.cropRotate;
  } else if (T is FilterEditor) {
    editorName = SubEditor.filter;
  } else if (T is BlurEditor) {
    editorName = SubEditor.blur;
  } else if (T is EmojiEditor) {
    editorName = SubEditor.emoji;
  }

  mainEditorCallbacks?.handleOpenSubEditor(editorName);
  _pageOpenCompleter = Completer();
  return Navigator.push<T?>(
    context,
    PageRouteBuilder(
      opaque: false,
      barrierColor: imageEditorTheme.subEditorPage.barrierColor,
      barrierDismissible: imageEditorTheme.subEditorPage.barrierDismissible,
      transitionDuration: duration,
      reverseTransitionDuration: duration,
      transitionsBuilder: imageEditorTheme.subEditorPage.transitionsBuilder ??
          (context, animation, secondaryAnimation, child) {
            return FadeTransition(
              opacity: animation,
              child: child,
            );
          },
      pageBuilder: (context, animation, secondaryAnimation) {
        void animationStatusListener(AnimationStatus status) {
          if (status == AnimationStatus.completed) {
            if (cropRotateEditor.currentState != null) {
              cropRotateEditor.currentState!.hideFakeHero();
            }
          } else if (status == AnimationStatus.dismissed) {
            setState(() {
              isSubEditorOpen = false;
              if (!_pageOpenCompleter.isCompleted) {
                _pageOpenCompleter.complete(true);
              }
              layerInteractionManager.freeStyleHighPerformanceHero = false;

              if (stateManager.heroScreenshotRequired) {
                stateManager.heroScreenshotRequired = false;
                _takeScreenshot();
              }
            });

            animation.removeStatusListener(animationStatusListener);
            mainEditorCallbacks?.handleCloseSubEditor(editorName);
          }
        }

        animation.addStatusListener(animationStatusListener);
        if (imageEditorTheme.subEditorPage.requireReposition) {
          return SafeArea(
            child: Stack(
              fit: StackFit.expand,
              children: [
                Positioned(
                  top: imageEditorTheme.subEditorPage.positionTop,
                  left: imageEditorTheme.subEditorPage.positionLeft,
                  right: imageEditorTheme.subEditorPage.positionRight,
                  bottom: imageEditorTheme.subEditorPage.positionBottom,
                  child: Center(
                    child: Container(
                      width: imageEditorTheme
                              .subEditorPage.enforceSizeFromMainEditor
                          ? sizesManager.lastScreenSize.width
                          : null,
                      height: imageEditorTheme
                              .subEditorPage.enforceSizeFromMainEditor
                          ? sizesManager.lastScreenSize.height
                          : null,
                      clipBehavior: Clip.hardEdge,
                      decoration: BoxDecoration(
                        borderRadius:
                            imageEditorTheme.subEditorPage.borderRadius,
                      ),
                      child: page,
                    ),
                  ),
                ),
              ],
            ),
          );
        } else {
          return page;
        }
      },
    ),
  );
}