Created
May 21, 2021 08:24
-
-
Save CoderJava/1d807f633c400d0f59fdeaa86de29744 to your computer and use it in GitHub Desktop.
Flutter camera preview (full screen)
This file contains 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