fluffychat/lib/pages/homeserver_picker/homeserver_picker_view.dart

181 lines
7.1 KiB
Dart
Raw Normal View History

2021-10-26 16:50:34 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2024-08-17 10:16:55 +00:00
import 'package:flutter_linkify/flutter_linkify.dart';
import 'package:url_launcher/url_launcher.dart';
2021-06-11 08:08:04 +00:00
2021-10-26 16:50:34 +00:00
import 'package:fluffychat/config/app_config.dart';
2022-04-15 09:42:59 +00:00
import 'package:fluffychat/widgets/layouts/login_scaffold.dart';
2023-09-22 06:26:43 +00:00
import 'package:fluffychat/widgets/matrix.dart';
import '../../config/themes.dart';
2021-11-09 20:32:16 +00:00
import 'homeserver_picker.dart';
2021-04-09 14:28:26 +00:00
2021-05-22 07:13:47 +00:00
class HomeserverPickerView extends StatelessWidget {
2021-04-09 14:28:26 +00:00
final HomeserverPickerController controller;
const HomeserverPickerView(this.controller, {super.key});
2021-04-09 14:28:26 +00:00
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
2022-04-15 09:42:59 +00:00
return LoginScaffold(
2023-09-22 06:26:43 +00:00
enforceMobileMode: Matrix.of(context).client.isLogged(),
2024-08-17 10:16:55 +00:00
appBar: controller.widget.addMultiAccount
? AppBar(
centerTitle: true,
title: Text(L10n.of(context)!.addAccount),
)
: null,
2024-08-28 06:43:21 +00:00
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
2023-12-24 12:46:29 +00:00
children: [
// display a prominent banner to import session for TOR browser
// users. This feature is just some UX sugar as TOR users are
// usually forced to logout as TOR browser is non-persistent
AnimatedContainer(
height: controller.isTorBrowser ? 64 : 0,
duration: FluffyThemes.animationDuration,
curve: FluffyThemes.animationCurve,
clipBehavior: Clip.hardEdge,
decoration: const BoxDecoration(),
child: Material(
clipBehavior: Clip.hardEdge,
2023-12-24 12:46:29 +00:00
borderRadius:
const BorderRadius.vertical(bottom: Radius.circular(8)),
color: theme.colorScheme.surface,
2023-12-24 12:46:29 +00:00
child: ListTile(
leading: const Icon(Icons.vpn_key),
title: Text(L10n.of(context)!.hydrateTor),
subtitle: Text(L10n.of(context)!.hydrateTorLong),
trailing: const Icon(Icons.chevron_right_outlined),
onTap: controller.restoreBackup,
),
),
2023-12-24 12:46:29 +00:00
),
2024-08-28 06:43:21 +00:00
if (MediaQuery.of(context).size.height > 512)
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height / 4,
),
child: Image.asset(
'assets/banner_transparent.png',
alignment: Alignment.center,
repeat: ImageRepeat.repeat,
),
),
2024-08-28 06:43:21 +00:00
Padding(
padding: const EdgeInsets.all(32.0),
child: TextField(
onChanged: controller.tryCheckHomeserverActionWithCooldown,
onEditingComplete:
controller.tryCheckHomeserverActionWithoutCooldown,
onSubmitted: controller.tryCheckHomeserverActionWithoutCooldown,
onTap: controller.tryCheckHomeserverActionWithCooldown,
controller: controller.homeserverController,
autocorrect: false,
keyboardType: TextInputType.url,
decoration: InputDecoration(
prefixIcon: controller.isLoading
? Container(
width: 16,
height: 16,
alignment: Alignment.center,
child: const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator.adaptive(
strokeWidth: 2,
),
),
)
: const Icon(Icons.search_outlined),
filled: false,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
hintText: AppConfig.defaultHomeserver,
labelText: L10n.of(context)!.homeserver,
errorText: controller.error,
suffixIcon: IconButton(
onPressed: () {
showDialog(
context: context,
builder: (context) => AlertDialog.adaptive(
title: Text(L10n.of(context)!.whatIsAHomeserver),
content: Linkify(
text: L10n.of(context)!.homeserverDescription,
),
actions: [
TextButton(
onPressed: () => launchUrl(
Uri.https('servers.joinmatrix.org'),
),
child: Text(
L10n.of(context)!.discoverHomeservers,
),
2024-08-28 06:43:21 +00:00
),
TextButton(
onPressed: Navigator.of(context).pop,
child: Text(L10n.of(context)!.close),
),
],
2023-12-24 12:46:29 +00:00
),
2024-08-28 06:43:21 +00:00
);
},
icon: const Icon(Icons.info_outlined),
),
),
),
),
if (MediaQuery.of(context).size.height > 512) const Spacer(),
ListView(
shrinkWrap: true,
padding: const EdgeInsets.symmetric(
horizontal: 32.0,
vertical: 32.0,
),
children: [
TextButton(
style: TextButton.styleFrom(
textStyle: theme.textTheme.labelMedium,
foregroundColor: theme.colorScheme.secondary,
),
onPressed: controller.isLoggingIn || controller.isLoading
? null
: controller.restoreBackup,
child: Text(L10n.of(context)!.hydrate),
),
if (controller.supportsPasswordLogin && controller.supportsSso)
TextButton(
style: TextButton.styleFrom(
foregroundColor: theme.colorScheme.secondary,
textStyle: theme.textTheme.labelMedium,
2023-12-24 12:46:29 +00:00
),
2024-08-28 06:43:21 +00:00
onPressed: controller.isLoggingIn || controller.isLoading
? null
: controller.login,
child: Text(L10n.of(context)!.loginWithMatrixId),
2024-08-17 10:16:55 +00:00
),
2024-08-28 06:43:21 +00:00
const SizedBox(height: 8.0),
if (controller.supportsPasswordLogin || controller.supportsSso)
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: theme.colorScheme.primary,
foregroundColor: theme.colorScheme.onPrimary,
2024-08-17 10:16:55 +00:00
),
2024-08-28 06:43:21 +00:00
onPressed: controller.isLoggingIn || controller.isLoading
? null
: controller.supportsSso
? controller.ssoLoginAction
2024-08-17 10:16:55 +00:00
: controller.login,
2024-08-28 06:43:21 +00:00
child: Text(L10n.of(context)!.next),
2024-08-17 10:16:55 +00:00
),
2024-08-28 06:43:21 +00:00
],
2023-07-22 11:00:27 +00:00
),
2024-08-17 10:16:55 +00:00
],
),
);
}
}