Skip to content

Instantly share code, notes, and snippets.

@intelguasoft
Forked from CoderJava/main.dart
Created November 3, 2022 15:33
Show Gist options
  • Save intelguasoft/156488a02681d1b743b8b91d731f5530 to your computer and use it in GitHub Desktop.
Save intelguasoft/156488a02681d1b743b8b91d731f5530 to your computer and use it in GitHub Desktop.
Flutter camera preview (full screen)
final mediaSize = MediaQuery.of(context).size;
final scale = 1 / (controller.value.aspectRatio * mediaSize.aspectRatio);
return ClipRect(
clipper: _MediaSizeClipper(mediaSize),
child: Transform.scale(
scale: scale,
alignment: Alignment.topCenter,
child: CameraPreview(controller),
),
);
class _MediaSizeClipper extends CustomClipper<Rect> {
final Size mediaSize;
const _MediaSizeClipper(this.mediaSize);
@override
Rect getClip(Size size) {
return Rect.fromLTWH(0, 0, mediaSize.width, mediaSize.height);
}
@override
bool shouldReclip(CustomClipper<Rect> oldClipper) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment