chore: Follow up nicer max width pages

This commit is contained in:
krille-chan 2024-07-26 17:57:30 +02:00
commit b20cee34d4
No known key found for this signature in database
2 changed files with 33 additions and 36 deletions

View file

@ -716,9 +716,10 @@ class ChatListController extends State<ChatList>
isDestructiveAction: true, isDestructiveAction: true,
); );
if (confirmed == OkCancelResult.cancel) return; if (confirmed == OkCancelResult.cancel) return;
if (!mounted) { if (!mounted) return;
await showFutureLoadingDialog(context: context, future: room.leave);
} await showFutureLoadingDialog(context: context, future: room.leave);
return; return;
} }
} }

View file

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