-
-
Save intelguasoft/156488a02681d1b743b8b91d731f5530 to your computer and use it in GitHub Desktop.
Flutter camera preview (full screen)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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