cameraView method

Widget cameraView()

Implementation

Widget cameraView() {
  return Stack(
    children: [
      kIsWeb
          ? Center(
              child: RepaintBoundary(
                key: _cameraPreviewKey,
                child: AspectRatio(
                  aspectRatio:
                      widget.controller.cameraController!.value.aspectRatio,
                  child: widget.controller.cameraController!.buildPreview(),
                ),
              ),
            )
          : RepaintBoundary(
              key: _cameraPreviewKey,
              child: CameraPreview(
                widget._controller.cameraController!,
                child: LayoutBuilder(builder: (context, constraints) {
                  return GestureDetector(
                    onTapUp: (details) =>
                        onViewFinderTap(details, constraints),
                    onScaleUpdate: (details) async {
                      final zoom = details.scale.clamp(1.0, 2.0);
                      widget._controller.cameraController?.setZoomLevel(zoom);
                    },
                  );
                }),
              ),
            ),
      if (widget.overlayWidget != null)
        Align(
          alignment: Alignment.center,
          child: KeyedSubtree(
            key: _overlayKey,
            child: widget.overlayWidget!,
          ),
        ),
      if (isCropping)
         Center(
           child: widget.loadingWidget ??
               CircularProgressIndicator(),
         ),
      imagePreviewButton(),
      Align(
          alignment: Alignment.bottomCenter,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              if (widget._controller.files.isNotEmpty)
                nextButton(
                  buttontitle: widget._controller.preview
                      ? buttonLabel('Next')
                      : buttonLabel('Done'),
                  imagelength: widget._controller.files.length.toString(),
                  onTap: () {
                    if (widget._controller.preview) {
                      if (widget._controller.cameraController != null) {
                        widget._controller.cameraController!.pausePreview();
                      }
                      setState(() {
                        currentIndex = widget._controller.files.length;
                        showPreviewPage = true;
                      });
                    } else {
                      if (widget._controller.minCount != null &&
                          (widget._controller.files.length <
                              widget._controller.minCount!)) {
                        final errorMessage = widget
                                ._controller.minCountMessage ??
                            Utils.translateWithFallback(
                                'ensemble.input.minCountMessage',
                                'Minimum ${widget._controller.minCount} capture are required');
                        ToastController().showToast(
                            context,
                            ShowToastAction(
                                type: ToastType.error,
                                message: errorMessage,
                                alignment: Alignment.topCenter,
                                dismissible: true,
                                duration: 3),
                            null);
                        return;
                      }
                      Navigator.pop(context, widget._controller.files);
                      widget.onComplete?.call();
                    }
                  },
                ),
              const SizedBox(height: 8),
              mediaThumbnail(),
              cameraButton(),
            ],
          )),
      ValueListenableBuilder(
        valueListenable: _focusState,
        builder: (context, state, child) {
          if (state == FocusState.success) {
            return Positioned(
              left: _offset!.dx,
              top: _offset!.dy,
              child: widget._controller.focusIcon != null
                  ? iconframework.Icon.fromModel(
                      widget._controller.focusIcon!)
                  : Icon(Icons.filter_tilt_shift, color: iconColor, size: 48),
            );
          }
          return const SizedBox.shrink();
        },
      ),
      ValueListenableBuilder<int>(
        valueListenable: widget._controller.intervalCountdown,
        builder: (context, value, child) {
          if (value <= 0 || widget._controller.intervalPause) {
            return const SizedBox.shrink();
          }
          return Center(
              child: Text(
            value.toString(),
            style: const TextStyle(
              fontWeight: FontWeight.bold,
              fontSize: 24,
              color: Colors.white,
              shadows: [
                Shadow(
                  offset: Offset(2.0, 2.0),
                  blurRadius: 3.0,
                  color: Colors.black,
                ),
              ],
            ),
          ));
        },
      ),
      if (modes.elementAt(currentModeIndex) == CameraMode.photo)
        Align(
          alignment: const Alignment(0.0, -0.8),
          child: ValueListenableBuilder<double?>(
            valueListenable: phoneAngle,
            builder: (context, angle, child) {
              if (angle != null &&
                  (angle < widget._controller.minAngle ||
                      angle > widget._controller.maxAngle)) {
                return Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 16),
                  child: Container(
                    decoration: BoxDecoration(
                      border: Border.all(color: iconColor),
                      color: Colors.black,
                    ),
                    padding: const EdgeInsets.all(16.0),
                    child: Text(
                      getAssistAngleMessage(),
                      style: TextStyle(color: iconColor, fontSize: 20),
                      textAlign: TextAlign.center,
                    ),
                  ),
                );
              }
              return const SizedBox.shrink();
            },
          ),
        ),
      if (modes.elementAt(currentModeIndex) == CameraMode.video)
        Align(
          alignment: const Alignment(0.0, -0.8),
          child: ValueListenableBuilder<double?>(
            valueListenable: phoneSpeed,
            builder: (context, speed, child) {
              if (speed != null && speed > widget._controller.maxSpeed) {
                return Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 16),
                  child: Container(
                    decoration: BoxDecoration(
                      border: Border.all(color: iconColor),
                      color: Colors.black,
                    ),
                    padding: const EdgeInsets.all(16.0),
                    child: Text(
                      getAssistSpeedMessage(),
                      style: TextStyle(color: iconColor, fontSize: 20),
                      textAlign: TextAlign.center,
                    ),
                  ),
                );
              }
              return const SizedBox.shrink();
            },
          ),
        )
    ],
  );
}