ios – Digicam preview not working in full display screen in flutter


Right here is a solution that ought to work

To repair the problem with the digicam preview not matching the display screen dimension, you may attempt the next modifications to the code:

  1. Change the Rework.scale widget with a AspectRatio widget to make sure that the digicam preview maintains the right side ratio:
AspectRatio(
  aspectRatio: _cameraController!.worth.aspectRatio,
  little one: CameraPreview(_cameraController!),
),
  1. Replace the scale property within the Rework.scale widget to regulate the preview dimension accurately:
scale: mediaSize.aspectRatio / _cameraController!.worth.aspectRatio,

This is the modified code:

Widget construct(BuildContext context) {
  closing mediaSize = MediaQuery.of(context).dimension;

  return Scaffold(
    extendBody: true,
    extendBodyBehindAppBar: true,
    appBar: AppBar(
      backgroundColor: Colours.clear,
      elevation: 0,
      main: Builder(
        builder: (BuildContext context) {
          return IconButton(
            onPressed: () {
              Navigator.pop(context);
            },
            icon: const Icon(
              UniconsLine.multiply,
              colour: Colours.white,
              dimension: 30,
            ),
          );
        },
      ),
    ),
    physique: FutureBuilder<void>(
      future: _initializeControllerFuture,
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.carried out) {
          // If the Future is full, show the preview.
          return AspectRatio(
            aspectRatio: _cameraController!.worth.aspectRatio,
            little one: CameraPreview(_cameraController!),
          );
        } else {
          // In any other case, show a loading indicator.
          return const Middle(little one: CircularProgressIndicator());
        }
      },
    ),
    floatingActionButton: FloatingActionButton(
      // Present an onPressed callback.
      onPressed: () async {
        // Take the Image in a attempt / catch block. If something goes improper,
        // catch the error.
        attempt {
          // Be sure that the digicam is initialized.
          await _initializeControllerFuture;

          // Try to take an image and get the file `picture`
          // the place it was saved.
          closing picture = await _cameraController?.takePicture();

          if (!mounted) return;

          // If the image was taken, show it on a brand new display screen.
          await Navigator.of(context).push(
            MaterialPageRoute(
              builder: (context) => DisplayPictureScreen(
                // Move the robotically generated path to
                // the DisplayPictureScreen widget.
                imagePath: picture!.path,
              ),
            ),
          );
        } catch (e) {
          // If an error happens, log the error to the console.
          print(e);
        }
      },
      little one: (widget.isVideo)
          ? const Icon(UniconsLine.video)
          : const Icon(UniconsLine.digicam),
    ),
    floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
  );
}

With these adjustments, the digicam preview ought to match the display screen dimension accurately.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles