Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/src/responsive_scaled_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ class ResponsiveScaledBox extends StatelessWidget {
final double? width;
final Widget child;
final bool autoCalculateMediaQueryData;
final bool autoScaleUp;

const ResponsiveScaledBox(
{super.key,
required this.width,
required this.child,
this.autoScaleUp = false,
this.autoCalculateMediaQueryData = true});

@override
Expand All @@ -20,13 +22,15 @@ class ResponsiveScaledBox extends StatelessWidget {
builder: (context, constraints) {
MediaQueryData mediaQueryData = MediaQuery.of(context);

double aspectRatio = constraints.maxWidth / constraints.maxHeight;
double availableWidth = constraints.maxWidth;
double availableHeight = constraints.maxHeight;

double aspectRatio = availableWidth / availableHeight;
double scaledWidth = width!;
double scaledHeight = width! / aspectRatio;

bool overrideMediaQueryData = autoCalculateMediaQueryData &&
(mediaQueryData.size ==
Size(constraints.maxWidth, constraints.maxHeight));
(mediaQueryData.size == Size(availableWidth, availableHeight));

EdgeInsets scaledViewInsets = getScaledViewInsets(
mediaQueryData: mediaQueryData,
Expand All @@ -50,6 +54,13 @@ class ResponsiveScaledBox extends StatelessWidget {
),
);

if (autoScaleUp && width! < availableWidth) {
childHolder = Transform.scale(
scale: availableWidth / width!,
child: childHolder,
);
}

if (overrideMediaQueryData) {
return MediaQuery(
data: mediaQueryData.copyWith(
Expand Down