|
@@ -37,59 +37,56 @@ class CroppedFaceImageView extends StatelessWidget {
|
|
|
future: getImage(),
|
|
|
builder: (context, snapshot) {
|
|
|
if (snapshot.hasData) {
|
|
|
- return LayoutBuilder(
|
|
|
- builder: (BuildContext context, BoxConstraints constraints) {
|
|
|
- final Image image = snapshot.data!;
|
|
|
-
|
|
|
- final double viewWidth = constraints.maxWidth;
|
|
|
- final double viewHeight = constraints.maxHeight;
|
|
|
-
|
|
|
- final faceBox = face.detection.box;
|
|
|
-
|
|
|
- final double relativeFaceCenterX =
|
|
|
- faceBox.xMin + faceBox.width / 2;
|
|
|
- final double relativeFaceCenterY =
|
|
|
- faceBox.yMin + faceBox.height / 2;
|
|
|
-
|
|
|
- const double desiredFaceHeightRelativeToWidget = 7 / 10;
|
|
|
- final double scale =
|
|
|
- (1 / faceBox.height) * desiredFaceHeightRelativeToWidget;
|
|
|
-
|
|
|
- final double widgetCenterX = viewWidth / 2;
|
|
|
- final double widgetCenterY = viewHeight / 2;
|
|
|
-
|
|
|
- final double imageAspectRatio = enteFile.width / enteFile.height;
|
|
|
- final double widgetAspectRatio = viewWidth / viewHeight;
|
|
|
- final double imageToWidgetRatio =
|
|
|
- imageAspectRatio / widgetAspectRatio;
|
|
|
-
|
|
|
- double offsetX =
|
|
|
- (widgetCenterX - relativeFaceCenterX * viewWidth) * scale;
|
|
|
- double offsetY =
|
|
|
- (widgetCenterY - relativeFaceCenterY * viewHeight) * scale;
|
|
|
-
|
|
|
- if (imageAspectRatio < widgetAspectRatio) {
|
|
|
- // Landscape Image: Adjust offsetX more conservatively
|
|
|
- offsetX = offsetX * imageToWidgetRatio;
|
|
|
- } else {
|
|
|
- // Portrait Image: Adjust offsetY more conservatively
|
|
|
- offsetY = offsetY / imageToWidgetRatio;
|
|
|
- }
|
|
|
-
|
|
|
- return ClipRRect(
|
|
|
- borderRadius: const BorderRadius.all(Radius.elliptical(16, 12)),
|
|
|
- child: Transform.translate(
|
|
|
- offset: Offset(
|
|
|
- offsetX,
|
|
|
- offsetY,
|
|
|
- ),
|
|
|
- child: Transform.scale(
|
|
|
- scale: scale,
|
|
|
- child: image,
|
|
|
- ),
|
|
|
+ final double imageAspectRatio = enteFile.width / enteFile.height;
|
|
|
+ final Image image = snapshot.data!;
|
|
|
+
|
|
|
+ const double viewWidth = 60;
|
|
|
+ const double viewHeight = 60;
|
|
|
+
|
|
|
+ final faceBox = face.detection.box;
|
|
|
+
|
|
|
+ final double relativeFaceCenterX = faceBox.xMin + faceBox.width / 2;
|
|
|
+ final double relativeFaceCenterY = faceBox.yMin + faceBox.height / 2;
|
|
|
+
|
|
|
+ const double desiredFaceHeightRelativeToWidget = 8 / 10;
|
|
|
+ final double scale =
|
|
|
+ (1 / faceBox.height) * desiredFaceHeightRelativeToWidget;
|
|
|
+
|
|
|
+ const double widgetCenterX = viewWidth / 2;
|
|
|
+ const double widgetCenterY = viewHeight / 2;
|
|
|
+
|
|
|
+ const double widgetAspectRatio = viewWidth / viewHeight;
|
|
|
+ final double imageToWidgetRatio =
|
|
|
+ imageAspectRatio / widgetAspectRatio;
|
|
|
+
|
|
|
+ double offsetX =
|
|
|
+ (widgetCenterX - relativeFaceCenterX * viewWidth) * scale;
|
|
|
+ double offsetY =
|
|
|
+ (widgetCenterY - relativeFaceCenterY * viewHeight) * scale;
|
|
|
+
|
|
|
+ if (imageAspectRatio < widgetAspectRatio) {
|
|
|
+ // Landscape Image: Adjust offsetX more conservatively
|
|
|
+ offsetX = offsetX * imageToWidgetRatio;
|
|
|
+ } else {
|
|
|
+ // Portrait Image: Adjust offsetY more conservatively
|
|
|
+ offsetY = offsetY / imageToWidgetRatio;
|
|
|
+ }
|
|
|
+ return SizedBox(
|
|
|
+ width: viewWidth,
|
|
|
+ height: viewHeight,
|
|
|
+ child: ClipRRect(
|
|
|
+ borderRadius: const BorderRadius.all(Radius.elliptical(16, 12)),
|
|
|
+ child: Transform.translate(
|
|
|
+ offset: Offset(
|
|
|
+ offsetX,
|
|
|
+ offsetY,
|
|
|
+ ),
|
|
|
+ child: Transform.scale(
|
|
|
+ scale: scale,
|
|
|
+ child: image,
|
|
|
),
|
|
|
- );
|
|
|
- },
|
|
|
+ ),
|
|
|
+ ),
|
|
|
);
|
|
|
} else {
|
|
|
if (snapshot.hasError) {
|