50 lines
1.3 KiB
Dart
50 lines
1.3 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
import 'app_breakpoints.dart';
|
|
|
|
class ResponsiveBody extends StatelessWidget {
|
|
const ResponsiveBody({
|
|
super.key,
|
|
required this.child,
|
|
this.maxWidth = 960,
|
|
this.padding = EdgeInsets.zero,
|
|
});
|
|
|
|
final Widget child;
|
|
final double maxWidth;
|
|
final EdgeInsetsGeometry padding;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
final height = constraints.hasBoundedHeight
|
|
? constraints.maxHeight
|
|
: MediaQuery.sizeOf(context).height;
|
|
final width = constraints.hasBoundedWidth
|
|
? constraints.maxWidth
|
|
: maxWidth;
|
|
final horizontalPadding = AppBreakpoints.horizontalPadding(width);
|
|
final boxConstraints = BoxConstraints(
|
|
maxWidth: maxWidth,
|
|
minHeight: height,
|
|
maxHeight: height,
|
|
);
|
|
|
|
return Padding(
|
|
padding: padding.add(
|
|
EdgeInsets.symmetric(horizontal: horizontalPadding),
|
|
),
|
|
child: Align(
|
|
alignment: Alignment.topCenter,
|
|
child: ConstrainedBox(
|
|
constraints: boxConstraints,
|
|
child: SizedBox(width: width, child: child),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|