2021-04-09 18:26:44 +02:00
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class MaxWidthBody extends StatelessWidget {
|
2021-11-19 20:28:17 +01:00
|
|
|
final Widget? child;
|
2021-04-09 18:26:44 +02:00
|
|
|
final double maxWidth;
|
|
|
|
final bool withScrolling;
|
|
|
|
|
|
|
|
const MaxWidthBody({
|
|
|
|
this.child,
|
|
|
|
this.maxWidth = 600,
|
|
|
|
this.withScrolling = false,
|
2021-11-19 20:28:17 +01:00
|
|
|
Key? key,
|
2021-04-09 18:26:44 +02:00
|
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
final padding = EdgeInsets.symmetric(
|
|
|
|
horizontal: max(0, (constraints.maxWidth - maxWidth) / 2),
|
|
|
|
);
|
|
|
|
return withScrolling
|
|
|
|
? SingleChildScrollView(
|
2021-10-14 18:09:30 +02:00
|
|
|
physics: const ScrollPhysics(),
|
2021-04-09 18:26:44 +02:00
|
|
|
child: Padding(
|
|
|
|
padding: padding,
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Padding(
|
|
|
|
padding: padding,
|
|
|
|
child: child,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|