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:
- Change the
Rework.scale
widget with aAspectRatio
widget to make sure that the digicam preview maintains the right side ratio:
AspectRatio(
aspectRatio: _cameraController!.worth.aspectRatio,
little one: CameraPreview(_cameraController!),
),
- Replace the
scale
property within theRework.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.