@@ -4,10 +4,12 @@ import 'package:camerawesome/camerawesome_plugin.dart';
44import 'package:flutter/cupertino.dart' ;
55import 'package:flutter/material.dart' ;
66
7- class CameraPreviewWidget extends StatelessWidget {
7+ /// This is a fullscreen camera preview
8+ /// some part of the preview are croped so we have a full sized camera preview
9+ class CameraPreviewCovered extends StatelessWidget {
810 final Widget ? loadingWidget;
911
10- const CameraPreviewWidget ({
12+ const CameraPreviewCovered ({
1113 super .key,
1214 this .loadingWidget,
1315 });
@@ -35,17 +37,7 @@ class CameraPreviewWidget extends StatelessWidget {
3537 .constrainSizeAndAttemptToPreserveAspectRatio (size);
3638 final textureId = data[1 ] as int ;
3739 final double ratio = size.height / size.width;
38- debugPrint ("- preview size: ${size .width }/${size .height }" );
39- debugPrint ("- ratio: $ratio " );
40- debugPrint (
41- "- pixelRatio: ${MediaQuery .of (context ).devicePixelRatio }" );
42- debugPrint (
43- "- max available size: ${constraints .maxWidth }/${constraints .maxHeight }" );
44- debugPrint ("==> maxSize $maxSize " );
45- debugPrint (
46- "- scale: ${_calculateScale (constraints , ratio , orientation )}" );
4740 var scale = size.height / maxSize.height;
48- debugPrint ("==> scale $scale " );
4941 return Container (
5042 height: constraints.maxHeight,
5143 width: constraints.maxWidth,
@@ -55,32 +47,9 @@ class CameraPreviewWidget extends StatelessWidget {
5547 scale: scale,
5648 child: AspectRatio (
5749 aspectRatio: ratio,
58- // child: SizedBox(
59- // height: orientation == Orientation.portrait
60- // ? constraints.maxHeight
61- // : constraints.maxWidth,
62- // width: orientation == Orientation.portrait
63- // ? constraints.maxWidth
64- // : constraints.maxHeight,
6550 child: Texture (textureId: textureId),
66- // ),
6751 ),
6852 ),
69- // child: Transform.scale(
70- // scale: _calculateScale(constraints, ratio, orientation),
71- // child: AspectRatio(
72- // aspectRatio: ratio,
73- // child: SizedBox(
74- // height: orientation == Orientation.portrait
75- // ? constraints.maxHeight
76- // : constraints.maxWidth,
77- // width: orientation == Orientation.portrait
78- // ? constraints.maxWidth
79- // : constraints.maxHeight,
80- // child: Texture(textureId: textureId),
81- // ),
82- // ),
83- // ),
8453 ),
8554 );
8655 },
@@ -90,20 +59,6 @@ class CameraPreviewWidget extends StatelessWidget {
9059 );
9160 }
9261
93- double _calculateScale (
94- BoxConstraints constraints,
95- double ratio,
96- Orientation orientation,
97- ) {
98- final aspectRatio = constraints.maxWidth / constraints.maxHeight;
99- var scale = ratio / aspectRatio;
100- if (ratio < aspectRatio) {
101- scale = 1 / scale;
102- }
103-
104- return scale;
105- }
106-
10762 Future <Size > previewSize () {
10863 return CamerawesomePlugin .getEffectivPreviewSize ();
10964 }
@@ -114,10 +69,13 @@ class CameraPreviewWidget extends StatelessWidget {
11469 }
11570}
11671
117- class RatioCameraPreviewWidget extends StatelessWidget {
72+ /// A preview for the camera that shows minimized
73+ /// (corresponds to css contains)
74+ /// The preview is minimized to be shown completely
75+ class MinimizedCameraPreviewWidget extends StatelessWidget {
11876 final Widget ? loadingWidget;
11977
120- const RatioCameraPreviewWidget ({
78+ const MinimizedCameraPreviewWidget ({
12179 super .key,
12280 this .loadingWidget,
12381 });
@@ -143,47 +101,21 @@ class RatioCameraPreviewWidget extends StatelessWidget {
143101 final size = data[0 ] as Size ;
144102 final textureId = data[1 ] as int ;
145103 final double ratio = size.height / size.width;
146- debugPrint ("- preview size: ${size .width }/${size .height }" );
147- debugPrint ("- ratio: $ratio " );
148- debugPrint (
149- "- pixelRatio: ${MediaQuery .of (context ).devicePixelRatio }" );
150- debugPrint (
151- "- max available size: ${constraints .maxWidth }/${constraints .maxHeight }" );
152- debugPrint (
153- "- scale: ${_calculateScale (constraints , ratio , orientation )}" );
154104 return Container (
155105 color: Colors .black,
156106 child: Center (
157- child: Transform .scale (
158- scale: 1 ,
159- child: AspectRatio (
160- aspectRatio: ratio,
161- child: SizedBox (
162- height: orientation == Orientation .portrait
163- ? constraints.maxHeight
164- : constraints.maxWidth,
165- width: orientation == Orientation .portrait
166- ? constraints.maxWidth
167- : constraints.maxHeight,
168- child: Texture (textureId: textureId),
169- ),
107+ child: AspectRatio (
108+ aspectRatio: ratio,
109+ child: SizedBox (
110+ height: orientation == Orientation .portrait
111+ ? constraints.maxHeight
112+ : constraints.maxWidth,
113+ width: orientation == Orientation .portrait
114+ ? constraints.maxWidth
115+ : constraints.maxHeight,
116+ child: Texture (textureId: textureId),
170117 ),
171118 ),
172- // child: Transform.scale(
173- // scale: _calculateScale(constraints, ratio, orientation),
174- // child: AspectRatio(
175- // aspectRatio: ratio,
176- // child: SizedBox(
177- // height: orientation == Orientation.portrait
178- // ? constraints.maxHeight
179- // : constraints.maxWidth,
180- // width: orientation == Orientation.portrait
181- // ? constraints.maxWidth
182- // : constraints.maxHeight,
183- // child: Texture(textureId: textureId),
184- // ),
185- // ),
186- // ),
187119 ),
188120 );
189121 },
0 commit comments