fluffychat/lib/widgets/layouts/one_page_card.dart

51 lines
1.6 KiB
Dart
Raw Normal View History

2021-11-19 20:28:17 +01:00
//@dart=2.12
2021-04-09 14:56:23 +02:00
import 'dart:math';
2021-10-26 18:50:34 +02:00
import 'package:flutter/material.dart';
2021-05-29 09:56:52 +02:00
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/widgets/matrix.dart';
2021-04-09 14:56:23 +02:00
class OnePageCard extends StatelessWidget {
final Widget child;
/// This will cause the "isLogged()" check to be skipped and force a
/// OnePageCard without login wallpaper. This can be used in situations where
/// "Matrix.of(context) is not yet available, e.g. in the LockScreen widget.
final bool forceBackgroundless;
const OnePageCard(
{Key? key, required this.child, this.forceBackgroundless = false})
: super(key: key);
2021-04-09 14:56:23 +02:00
2021-05-01 07:45:11 +02:00
static const int alpha = 12;
2021-05-29 09:56:52 +02:00
static num breakpoint = FluffyThemes.columnWidth * 2;
2021-04-09 14:56:23 +02:00
@override
Widget build(BuildContext context) {
2021-11-15 09:48:21 +01:00
final horizontalPadding =
2021-11-19 20:28:17 +01:00
max<double>((MediaQuery.of(context).size.width - 600) / 2, 24);
return MediaQuery.of(context).size.width <= breakpoint ||
forceBackgroundless ||
Matrix.of(context).client.isLogged()
? child
: Container(
2021-10-14 18:09:30 +02:00
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/login_wallpaper.jpg'),
fit: BoxFit.cover,
),
),
child: Padding(
2021-11-15 09:48:21 +01:00
padding: EdgeInsets.only(
top: 16,
left: horizontalPadding,
right: horizontalPadding,
bottom: max((MediaQuery.of(context).size.height - 600) / 2, 24),
),
2021-11-15 09:48:21 +01:00
child: SafeArea(child: Card(elevation: 16, child: child)),
),
);
2021-04-09 14:56:23 +02:00
}
}