fluffychat/lib/pages/homeserver_picker/homeserver_picker_view.dart

162 lines
6.6 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';
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';
import 'homeserver_app_bar.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;
2022-01-29 11:35:03 +00:00
const HomeserverPickerView(this.controller, {Key? key}) : super(key: key);
2021-04-09 14:28:26 +00:00
@override
Widget build(BuildContext context) {
final benchmarkResults = controller.benchmarkResults;
2022-04-15 09:42:59 +00:00
return LoginScaffold(
2022-10-16 10:37:38 +00:00
body: Column(
children: [
HomeserverAppBar(controller: controller),
2022-10-16 10:37:38 +00:00
// 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: const Duration(milliseconds: 300),
clipBehavior: Clip.hardEdge,
curve: Curves.bounceInOut,
decoration: const BoxDecoration(),
child: Material(
clipBehavior: Clip.hardEdge,
2022-10-16 10:37:38 +00:00
borderRadius:
const BorderRadius.vertical(bottom: Radius.circular(8)),
color: Theme.of(context).colorScheme.surface,
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,
),
),
2022-10-16 10:37:38 +00:00
),
Expanded(
child: ListView(
children: [
if (controller.displayServerList)
2022-08-05 19:04:37 +00:00
Padding(
padding: const EdgeInsets.all(12.0),
2022-10-16 10:37:38 +00:00
child: Material(
borderRadius:
BorderRadius.circular(AppConfig.borderRadius),
color: Theme.of(context).colorScheme.onInverseSurface,
clipBehavior: Clip.hardEdge,
child: benchmarkResults == null
? const Center(
child: Padding(
padding: EdgeInsets.all(12.0),
child: CircularProgressIndicator.adaptive(),
))
: Column(
children: controller.filteredHomeservers
.map(
(server) => ListTile(
trailing: IconButton(
icon: const Icon(
Icons.info_outlined,
color: Colors.black,
),
2022-10-16 10:37:38 +00:00
onPressed: () =>
controller.showServerInfo(server),
),
onTap: () => controller.setServer(
server.homeserver.baseUrl.host),
title: Text(
server.homeserver.baseUrl.host,
style: const TextStyle(
color: Colors.black),
),
subtitle: Text(
server.homeserver.description ?? '',
style: TextStyle(
color: Colors.grey.shade700),
),
2022-10-16 10:37:38 +00:00
),
)
.toList(),
),
),
)
2022-11-04 10:17:22 +00:00
else ...[
Container(
alignment: Alignment.center,
height: 200,
child: Image.asset(
'assets/info-logo.png',
filterQuality: FilterQuality.medium,
),
),
2022-10-16 10:37:38 +00:00
Padding(
2022-11-04 10:17:22 +00:00
padding: const EdgeInsets.symmetric(horizontal: 16.0),
2022-10-16 10:37:38 +00:00
child: Center(
child: Text(
AppConfig.applicationWelcomeMessage ??
L10n.of(context)!.welcomeText,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 20),
),
),
2022-10-16 10:37:38 +00:00
),
2022-11-04 10:17:22 +00:00
],
2022-10-16 10:37:38 +00:00
],
2021-11-15 08:48:21 +00:00
),
2022-10-16 10:37:38 +00:00
),
SafeArea(
child: Container(
padding: const EdgeInsets.all(12),
width: double.infinity,
2022-10-16 10:37:38 +00:00
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextButton(
style: TextButton.styleFrom(
foregroundColor:
Theme.of(context).colorScheme.onSurfaceVariant,
),
onPressed: controller.restoreBackup,
child: Text(L10n.of(context)!.hydrate),
),
TextButton(
onPressed: () => launch(AppConfig.privacyUrl),
child: Text(L10n.of(context)!.privacy),
),
Hero(
tag: 'loginButton',
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor:
Theme.of(context).colorScheme.onPrimary,
),
onPressed: controller.isLoading
? null
: controller.checkHomeserverAction,
child: controller.isLoading
? const LinearProgressIndicator()
: Text(L10n.of(context)!.connect),
),
),
],
),
),
2022-10-16 10:37:38 +00:00
),
],
2021-04-09 14:28:26 +00:00
),
);
}
}