Files
tatuchat/lib/pages/intro/intro_page.dart
Welton Moura 0037b0b9cf
Some checks failed
Main Deploy Workflow / deploy_web (push) Has been cancelled
Main Deploy Workflow / deploy_playstore_internal (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
Initial commit
2026-09-11 15:59:56 -03:00

200 lines
7.7 KiB
Dart

// SPDX-FileCopyrightText: 2019-Present Christian Kußowski
// SPDX-FileCopyrightText: 2019-Present Contributors to FluffyChat
//
// SPDX-License-Identifier: AGPL-3.0-or-later
import 'package:tatchat/config/setting_keys.dart';
import 'package:tatchat/l10n/l10n.dart';
import 'package:tatchat/pages/intro/flows/restore_backup_flow.dart';
import 'package:tatchat/utils/platform_infos.dart';
import 'package:tatchat/widgets/layouts/login_scaffold.dart';
import 'package:tatchat/widgets/matrix.dart';
import 'package:go_router/go_router.dart';
import 'package:material_ui/material_ui.dart';
import 'package:url_launcher/url_launcher_string.dart';
class IntroPage extends StatelessWidget {
final bool isLoading, hasPresetHomeserver;
final String? loggingInToHomeserver, welcomeText;
final VoidCallback login, register;
const IntroPage({
required this.isLoading,
required this.loggingInToHomeserver,
super.key,
required this.hasPresetHomeserver,
required this.welcomeText,
required this.login,
required this.register,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final addMultiAccount = Matrix.of(
context,
).widget.clients.any((client) => client.isLogged());
final loggingInToHomeserver = this.loggingInToHomeserver;
return LoginScaffold(
appBar: AppBar(
centerTitle: true,
title: addMultiAccount
? Text(L10n.of(context).addAccount)
: Text(AppSettings.applicationName.value),
actions: [
PopupMenuButton(
useRootNavigator: true,
itemBuilder: (_) => [
PopupMenuItem(
onTap: isLoading ? null : () => restoreBackupFlow(context),
child: Row(
mainAxisSize: .min,
spacing: 12,
children: [
const Icon(Icons.import_export_outlined),
Expanded(
child: Text(
L10n.of(context).hydrate,
maxLines: 1,
overflow: .ellipsis,
),
),
],
),
),
PopupMenuItem(
onTap: () => launchUrlString(AppSettings.privacyPolicy.value),
child: Row(
mainAxisSize: .min,
spacing: 12,
children: [
const Icon(Icons.privacy_tip_outlined),
Text(L10n.of(context).privacy),
],
),
),
PopupMenuItem(
onTap: () => PlatformInfos.showDialog(context),
child: Row(
mainAxisSize: .min,
spacing: 12,
children: [
const Icon(Icons.info_outlined),
Text(L10n.of(context).about),
],
),
),
],
),
],
),
body: isLoading
? Center(
child: Column(
mainAxisAlignment: .center,
children: [
CircularProgressIndicator.adaptive(),
if (loggingInToHomeserver != null)
Text(L10n.of(context).logInTo(loggingInToHomeserver)),
],
),
)
: LayoutBuilder(
builder: (context, constraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraints.maxHeight,
),
child: IntrinsicHeight(
child: Column(
children: [
Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(32.0),
child: Hero(
tag: 'info-logo',
child: ClipRRect(
borderRadius: BorderRadius.circular(128),
child: Image.asset(
'./assets/logo/mini/logo_mini.png',
width: 128,
height: 128,
),
),
),
),
Text(
L10n.of(context).appSubtitle,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 20),
),
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Text(
welcomeText ?? L10n.of(context).appDescription,
textAlign: TextAlign.center,
),
),
const Spacer(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Column(
mainAxisSize: .min,
crossAxisAlignment: .stretch,
children: [
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor:
theme.colorScheme.secondary,
foregroundColor:
theme.colorScheme.onSecondary,
),
onPressed: hasPresetHomeserver
? register
: () => context.go(
'${GoRouterState.of(context).uri.path}/sign_up',
),
child: Text(
L10n.of(context).createNewAccount,
),
),
SizedBox(height: 16),
ElevatedButton(
onPressed: login,
child: Text(L10n.of(context).signIn),
),
if (!hasPresetHomeserver)
TextButton(
onPressed: () async {
final client = await Matrix.of(
context,
).getLoginClient();
if (!context.mounted) return;
context.go(
'${GoRouterState.of(context).uri.path}/login',
extra: client,
);
},
child: Text(
L10n.of(context).loginWithMatrixId,
),
),
],
),
),
const SizedBox(height: 36),
],
),
),
),
);
},
),
);
}
}