|
|
|
|
@ -1,20 +1,17 @@
|
|
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
|
|
|
|
import 'package:fluffychat/config/themes.dart';
|
|
|
|
|
|
|
|
|
|
class MaxWidthBody extends StatelessWidget {
|
|
|
|
|
final Widget? child;
|
|
|
|
|
final Widget child;
|
|
|
|
|
final double maxWidth;
|
|
|
|
|
final bool withFrame;
|
|
|
|
|
final bool withScrolling;
|
|
|
|
|
final EdgeInsets? innerPadding;
|
|
|
|
|
|
|
|
|
|
const MaxWidthBody({
|
|
|
|
|
this.child,
|
|
|
|
|
required this.child,
|
|
|
|
|
this.maxWidth = 600,
|
|
|
|
|
this.withFrame = true,
|
|
|
|
|
this.withScrolling = true,
|
|
|
|
|
this.innerPadding,
|
|
|
|
|
super.key,
|
|
|
|
|
@ -24,36 +21,35 @@ class MaxWidthBody extends StatelessWidget {
|
|
|
|
|
return SafeArea(
|
|
|
|
|
child: LayoutBuilder(
|
|
|
|
|
builder: (context, constraints) {
|
|
|
|
|
final paddingVal = max(0, (constraints.maxWidth - maxWidth) / 2);
|
|
|
|
|
final hasPadding = paddingVal > 0;
|
|
|
|
|
final padding = EdgeInsets.symmetric(
|
|
|
|
|
vertical: hasPadding ? 32 : 0,
|
|
|
|
|
horizontal: max(0, (constraints.maxWidth - maxWidth) / 2),
|
|
|
|
|
);
|
|
|
|
|
final childWithPadding = Padding(
|
|
|
|
|
padding: padding,
|
|
|
|
|
child: withFrame && hasPadding
|
|
|
|
|
? Material(
|
|
|
|
|
elevation:
|
|
|
|
|
Theme.of(context).appBarTheme.scrolledUnderElevation ??
|
|
|
|
|
4,
|
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
|
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
|
|
|
|
|
shadowColor: Theme.of(context).appBarTheme.shadowColor,
|
|
|
|
|
child: child,
|
|
|
|
|
)
|
|
|
|
|
: child,
|
|
|
|
|
);
|
|
|
|
|
if (!withScrolling) {
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: innerPadding ?? EdgeInsets.zero,
|
|
|
|
|
child: childWithPadding,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
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.of(context)
|
|
|
|
|
.appBarTheme
|
|
|
|
|
.scrolledUnderElevation ??
|
|
|
|
|
4,
|
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
|
borderRadius:
|
|
|
|
|
BorderRadius.circular(AppConfig.borderRadius),
|
|
|
|
|
shadowColor: Theme.of(context).appBarTheme.shadowColor,
|
|
|
|
|
child: child,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
if (!withScrolling) return body;
|
|
|
|
|
|
|
|
|
|
return SingleChildScrollView(
|
|
|
|
|
padding: innerPadding,
|
|
|
|
|
physics: const ScrollPhysics(),
|
|
|
|
|
child: childWithPadding,
|
|
|
|
|
child: body,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
|