fluffychat/lib/widgets/layouts/login_scaffold.dart

142 lines
4.6 KiB
Dart
Raw Normal View History

2022-04-15 11:42:59 +02:00
import 'package:flutter/material.dart';
2022-10-16 12:37:38 +02:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:url_launcher/url_launcher_string.dart';
2022-10-16 12:37:38 +02:00
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/utils/platform_infos.dart';
2022-04-15 11:42:59 +02:00
class LoginScaffold extends StatelessWidget {
final Widget body;
final AppBar? appBar;
const LoginScaffold({
Key? key,
required this.body,
this.appBar,
}) : super(key: key);
@override
Widget build(BuildContext context) {
2022-10-16 12:37:38 +02:00
final isMobileMode = !FluffyThemes.isColumnMode(context);
2022-11-04 11:17:22 +01:00
final scaffold = Scaffold(
key: const Key('LoginScaffold'),
2022-11-04 11:17:22 +01:00
backgroundColor: isMobileMode ? null : Colors.transparent,
appBar: appBar == null
? null
: AppBar(
titleSpacing: appBar?.titleSpacing,
automaticallyImplyLeading:
appBar?.automaticallyImplyLeading ?? true,
centerTitle: appBar?.centerTitle,
title: appBar?.title,
leading: appBar?.leading,
actions: appBar?.actions,
backgroundColor: isMobileMode ? null : Colors.transparent,
),
extendBodyBehindAppBar: true,
extendBody: true,
body: body,
bottomNavigationBar: isMobileMode
? Material(
color: Theme.of(context).colorScheme.onInverseSurface,
child: const _PrivacyButtons(
mainAxisAlignment: MainAxisAlignment.center,
),
)
: null,
2022-11-04 11:17:22 +01:00
);
if (isMobileMode) return scaffold;
final colorScheme = Theme.of(context).colorScheme;
2022-10-16 12:37:38 +02:00
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
colors: [
colorScheme.primaryContainer.withAlpha(64),
colorScheme.secondaryContainer.withAlpha(64),
colorScheme.tertiaryContainer.withAlpha(64),
colorScheme.primaryContainer.withAlpha(64),
],
2022-10-16 12:37:38 +02:00
),
),
child: Column(
children: [
const SizedBox(height: 64),
Expanded(
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Material(
color: Theme.of(context).scaffoldBackgroundColor,
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
clipBehavior: Clip.hardEdge,
elevation:
Theme.of(context).appBarTheme.scrolledUnderElevation ?? 4,
shadowColor: Theme.of(context).appBarTheme.shadowColor,
child: ConstrainedBox(
constraints: isMobileMode
? const BoxConstraints()
: const BoxConstraints(maxWidth: 960, maxHeight: 640),
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Image.asset(
'assets/login_wallpaper.png',
fit: BoxFit.cover,
),
),
Container(
width: 1,
color: Theme.of(context).dividerTheme.color,
),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: scaffold,
),
),
],
),
),
),
),
2022-12-29 20:38:13 +01:00
),
2022-04-15 11:42:59 +02:00
),
const _PrivacyButtons(mainAxisAlignment: MainAxisAlignment.end),
],
),
);
}
}
class _PrivacyButtons extends StatelessWidget {
final MainAxisAlignment mainAxisAlignment;
const _PrivacyButtons({required this.mainAxisAlignment});
@override
Widget build(BuildContext context) {
return SizedBox(
height: 64,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: mainAxisAlignment,
children: [
TextButton(
onPressed: () => PlatformInfos.showDialog(context),
child: Text(L10n.of(context)!.about),
),
TextButton(
onPressed: () => launchUrlString(AppConfig.privacyUrl),
child: Text(L10n.of(context)!.privacy),
),
],
2022-04-15 11:42:59 +02:00
),
),
);
}
}