47 lines
1.1 KiB
Dart
47 lines
1.1 KiB
Dart
import 'package:flutter/widgets.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 width = constraints.maxWidth;
|
|
final horizontalPadding = switch (width) {
|
|
>= 1200 => 96.0,
|
|
>= 900 => 64.0,
|
|
>= 600 => 32.0,
|
|
_ => 16.0,
|
|
};
|
|
|
|
return Padding(
|
|
padding: padding.add(
|
|
EdgeInsets.symmetric(horizontal: horizontalPadding),
|
|
),
|
|
child: Align(
|
|
alignment: Alignment.topCenter,
|
|
child: ConstrainedBox(
|
|
constraints: BoxConstraints(maxWidth: maxWidth),
|
|
child: SizedBox(
|
|
width: double.infinity,
|
|
height: constraints.maxHeight,
|
|
child: child,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|