[mob] Remove unnecessary LayoutBuilder
This commit is contained in:
parent
8225697e43
commit
3253a2bf26
1 changed files with 41 additions and 44 deletions
|
@ -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 imageAspectRatio = enteFile.width / enteFile.height;
|
||||
final Image image = snapshot.data!;
|
||||
|
||||
final double viewWidth = constraints.maxWidth;
|
||||
final double viewHeight = constraints.maxHeight;
|
||||
const double viewWidth = 60;
|
||||
const double viewHeight = 60;
|
||||
|
||||
final faceBox = face.detection.box;
|
||||
final faceBox = face.detection.box;
|
||||
|
||||
final double relativeFaceCenterX =
|
||||
faceBox.xMin + faceBox.width / 2;
|
||||
final double relativeFaceCenterY =
|
||||
faceBox.yMin + faceBox.height / 2;
|
||||
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;
|
||||
const double desiredFaceHeightRelativeToWidget = 8 / 10;
|
||||
final double scale =
|
||||
(1 / faceBox.height) * desiredFaceHeightRelativeToWidget;
|
||||
|
||||
final double widgetCenterX = viewWidth / 2;
|
||||
final double widgetCenterY = viewHeight / 2;
|
||||
const double widgetCenterX = viewWidth / 2;
|
||||
const double widgetCenterY = viewHeight / 2;
|
||||
|
||||
final double imageAspectRatio = enteFile.width / enteFile.height;
|
||||
final double widgetAspectRatio = viewWidth / viewHeight;
|
||||
final double imageToWidgetRatio =
|
||||
imageAspectRatio / widgetAspectRatio;
|
||||
const double widgetAspectRatio = viewWidth / viewHeight;
|
||||
final double imageToWidgetRatio =
|
||||
imageAspectRatio / widgetAspectRatio;
|
||||
|
||||
double offsetX =
|
||||
(widgetCenterX - relativeFaceCenterX * viewWidth) * scale;
|
||||
double offsetY =
|
||||
(widgetCenterY - relativeFaceCenterY * viewHeight) * scale;
|
||||
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,
|
||||
),
|
||||
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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue