fluffychat/lib/widgets/layouts/max_width_body.dart

58 lines
1.7 KiB
Dart
Raw Normal View History

2021-04-09 16:26:44 +00:00
import 'package:flutter/material.dart';
import 'package:fluffychat/config/app_config.dart';
2024-07-26 15:57:30 +00:00
import 'package:fluffychat/config/themes.dart';
2021-04-09 16:26:44 +00:00
class MaxWidthBody extends StatelessWidget {
2024-07-26 15:57:30 +00:00
final Widget child;
2021-04-09 16:26:44 +00:00
final double maxWidth;
final bool withScrolling;
2024-01-07 09:43:51 +00:00
final EdgeInsets? innerPadding;
2021-04-09 16:26:44 +00:00
const MaxWidthBody({
2024-07-26 15:57:30 +00:00
required this.child,
2021-04-09 16:26:44 +00:00
this.maxWidth = 600,
this.withScrolling = true,
2024-01-07 09:43:51 +00:00
this.innerPadding,
super.key,
});
2021-04-09 16:26:44 +00:00
@override
Widget build(BuildContext context) {
return SafeArea(
child: LayoutBuilder(
builder: (context, constraints) {
final theme = Theme.of(context);
2024-07-26 15:57:30 +00:00
const desiredWidth = FluffyThemes.columnWidth * 1.5;
final body = constraints.maxWidth <= desiredWidth
? child
: Container(
alignment: Alignment.topCenter,
padding: const EdgeInsets.all(32),
child: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: FluffyThemes.columnWidth * 1.5,
),
child: Material(
elevation: theme.appBarTheme.scrolledUnderElevation ?? 4,
2024-07-26 15:57:30 +00:00
clipBehavior: Clip.hardEdge,
borderRadius:
BorderRadius.circular(AppConfig.borderRadius),
shadowColor: theme.appBarTheme.shadowColor,
2024-07-26 15:57:30 +00:00
child: child,
),
),
);
if (!withScrolling) return body;
return SingleChildScrollView(
2024-01-07 09:43:51 +00:00
padding: innerPadding,
physics: const ScrollPhysics(),
2024-07-26 15:57:30 +00:00
child: body,
);
},
),
2021-04-09 16:26:44 +00:00
);
}
}