Skip to content

Commit c98c5c0

Browse files
committed
MaxWidthBox Creation #2
- Set MaxWidth MediaQueryData.
1 parent 6d6f690 commit c98c5c0

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

lib/max_width_box.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@ class MaxWidthBox extends StatelessWidget {
2222

2323
@override
2424
Widget build(BuildContext context) {
25+
MediaQueryData mediaQuery = MediaQuery.of(context);
26+
27+
if (maxWidth != null) {
28+
if (mediaQuery.size.width > maxWidth!) {
29+
mediaQuery =
30+
mediaQuery.copyWith(size: Size(maxWidth!, mediaQuery.size.height));
31+
}
32+
}
33+
2534
return Stack(
2635
alignment: alignment,
2736
children: [
2837
background ?? const SizedBox.shrink(),
29-
SizedBox(width: maxWidth, child: child),
38+
MediaQuery(
39+
data: mediaQuery, child: SizedBox(width: maxWidth, child: child)),
3040
],
3141
);
3242
}

0 commit comments

Comments
 (0)