fluffychat/lib/pages/homeserver_picker/homeserver_picker_view.dart

161 lines
7.1 KiB
Dart
Raw Normal View History

2021-10-26 18:50:34 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2023-01-26 09:47:30 +01:00
import 'package:url_launcher/url_launcher_string.dart';
2021-06-11 10:08:04 +02:00
2021-10-26 18:50:34 +02:00
import 'package:fluffychat/config/app_config.dart';
2022-04-15 11:42:59 +02:00
import 'package:fluffychat/widgets/layouts/login_scaffold.dart';
import '../../config/themes.dart';
import 'homeserver_app_bar.dart';
2021-11-09 21:32:16 +01:00
import 'homeserver_picker.dart';
2021-04-09 16:28:26 +02:00
2021-05-22 09:13:47 +02:00
class HomeserverPickerView extends StatelessWidget {
2021-04-09 16:28:26 +02:00
final HomeserverPickerController controller;
2022-01-29 12:35:03 +01:00
const HomeserverPickerView(this.controller, {Key? key}) : super(key: key);
2021-04-09 16:28:26 +02:00
@override
Widget build(BuildContext context) {
final benchmarkResults = controller.benchmarkResults;
2022-04-15 11:42:59 +02:00
return LoginScaffold(
body: SafeArea(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(12.0),
child: HomeserverAppBar(controller: controller),
),
// 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,
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,
),
),
),
Expanded(
2022-12-29 20:38:13 +01:00
child: controller.displayServerList
? ListView(
children: [
if (controller.displayServerList)
Padding(
padding: const EdgeInsets.all(12.0),
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(),
),
)
2022-12-29 20:38:13 +01:00
: Column(
children: controller.filteredHomeservers
.map(
(server) => ListTile(
trailing: IconButton(
icon: const Icon(
Icons.info_outlined,
color: Colors.black,
),
onPressed: () => controller
.showServerInfo(server),
),
onTap: () => controller.setServer(
server.homeserver.baseUrl.host,
),
2022-12-29 20:38:13 +01:00
title: Text(
server.homeserver.baseUrl.host,
style: const TextStyle(
color: Colors.black,
),
2022-12-29 20:38:13 +01:00
),
subtitle: Text(
server.homeserver.description ??
'',
style: TextStyle(
color: Colors.grey.shade700,
),
2022-12-29 20:38:13 +01:00
),
),
)
.toList(),
),
),
),
],
)
2022-12-29 20:38:13 +01:00
: Container(
alignment: Alignment.topCenter,
child: Image.asset(
2022-12-29 20:38:13 +01:00
'assets/banner_transparent.png',
filterQuality: FilterQuality.medium,
),
2022-11-04 11:17:22 +01:00
),
2021-11-15 09:48:21 +01:00
),
SafeArea(
child: Container(
padding: const EdgeInsets.all(12),
width: double.infinity,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TextButton(
2023-01-26 09:47:30 +01:00
onPressed: () => launchUrlString(AppConfig.privacyUrl),
child: Text(L10n.of(context)!.privacy),
),
2022-12-29 20:38:13 +01:00
TextButton(
onPressed: controller.restoreBackup,
child: Text(L10n.of(context)!.hydrate),
),
Hero(
tag: 'loginButton',
2022-12-29 20:38:13 +01:00
child: ElevatedButton.icon(
style: ElevatedButton.styleFrom(
backgroundColor:
Theme.of(context).colorScheme.primary,
foregroundColor:
Theme.of(context).colorScheme.onPrimary,
),
onPressed: controller.isLoading
? null
: controller.checkHomeserverAction,
2022-12-29 20:38:13 +01:00
icon: const Icon(Icons.start_outlined),
label: controller.isLoading
? const LinearProgressIndicator()
2022-12-29 20:38:13 +01:00
: Text(L10n.of(context)!.letsStart),
),
),
],
),
),
),
],
),
2021-04-09 16:28:26 +02:00
),
);
}
}