Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scaling up #191

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
19 changes: 15 additions & 4 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 @@ -40,7 +44,7 @@ class ResponsiveScaledBox extends StatelessWidget {
padding: scaledViewPadding, insets: scaledViewInsets);

Widget childHolder = FittedBox(
fit: BoxFit.fitWidth,
fit: BoxFit.cover,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't change this for everyone.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed and return that back to Boxfit.fitWidth, actually in my tests it doesn't make any difference to output result because of respecting to aspect ratio.

alignment: Alignment.topCenter,
child: Container(
width: width,
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