2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2022-05-21 10:46:39 +02:00
|
|
|
import 'package:animations/animations.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2021-06-11 10:08:04 +02:00
|
|
|
import 'package:vrouter/vrouter.dart';
|
|
|
|
|
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/config/themes.dart';
|
2022-05-21 10:46:39 +02:00
|
|
|
import 'package:fluffychat/pages/homeserver_picker/homeserver_tile.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
2022-04-15 11:42:59 +02:00
|
|
|
import 'package:fluffychat/widgets/layouts/login_scaffold.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) {
|
2022-04-15 14:31:57 +02:00
|
|
|
final benchmarkResults = controller.benchmarkResults;
|
2022-04-15 11:42:59 +02:00
|
|
|
return LoginScaffold(
|
|
|
|
appBar: VRouter.of(context).path == '/home'
|
|
|
|
? null
|
|
|
|
: AppBar(title: Text(L10n.of(context)!.addAccount)),
|
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: ListView(
|
|
|
|
children: [
|
2022-04-15 14:31:57 +02:00
|
|
|
AnimatedContainer(
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
constraints: BoxConstraints(
|
|
|
|
maxHeight: controller.displayServerList ? 0 : 256),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: Image.asset('assets/info-logo.png'),
|
2021-11-15 12:14:00 +01:00
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: TextField(
|
2022-04-15 14:31:57 +02:00
|
|
|
focusNode: controller.homeserverFocusNode,
|
2022-04-15 11:42:59 +02:00
|
|
|
controller: controller.homeserverController,
|
2022-04-15 14:31:57 +02:00
|
|
|
onChanged: controller.onChanged,
|
2022-04-24 07:57:08 +02:00
|
|
|
style: FluffyThemes.loginTextFieldStyle,
|
2022-04-15 11:42:59 +02:00
|
|
|
decoration: FluffyThemes.loginTextFieldDecoration(
|
|
|
|
labelText: L10n.of(context)!.homeserver,
|
|
|
|
hintText: L10n.of(context)!.enterYourHomeserver,
|
2022-04-24 07:57:08 +02:00
|
|
|
suffixIcon: const Icon(
|
|
|
|
Icons.search,
|
|
|
|
color: Colors.black,
|
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
errorText: controller.error,
|
|
|
|
),
|
|
|
|
readOnly: !AppConfig.allowOtherHomeservers,
|
|
|
|
onSubmitted: (_) => controller.checkHomeserverAction(),
|
|
|
|
autocorrect: false,
|
2021-11-15 12:14:00 +01:00
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
),
|
2022-04-15 14:31:57 +02:00
|
|
|
if (controller.displayServerList)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Material(
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.circular(AppConfig.borderRadius),
|
|
|
|
color: Colors.white.withAlpha(200),
|
|
|
|
clipBehavior: Clip.hardEdge,
|
2022-05-21 10:46:39 +02:00
|
|
|
child: PageTransitionSwitcher(
|
|
|
|
transitionBuilder: (
|
|
|
|
Widget child,
|
|
|
|
Animation<double> primaryAnimation,
|
|
|
|
Animation<double> secondaryAnimation,
|
|
|
|
) {
|
|
|
|
return SharedAxisTransition(
|
|
|
|
animation: primaryAnimation,
|
|
|
|
secondaryAnimation: secondaryAnimation,
|
|
|
|
transitionType: SharedAxisTransitionType.scaled,
|
|
|
|
child: child,
|
|
|
|
fillColor: Colors.transparent,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: ListTileTheme(
|
|
|
|
data: const ListTileThemeData(
|
|
|
|
iconColor: Colors.black,
|
|
|
|
textColor: Colors.black,
|
|
|
|
),
|
|
|
|
key: ValueKey(benchmarkResults),
|
|
|
|
child: benchmarkResults == null
|
|
|
|
? Center(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const CircularProgressIndicator
|
|
|
|
.adaptive(),
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(Icons.rocket),
|
|
|
|
title: Text(L10n.of(context)!
|
|
|
|
.benchmarkingHomeserver),
|
2022-04-15 14:31:57 +02:00
|
|
|
),
|
2022-05-21 10:46:39 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
))
|
|
|
|
: ListView.builder(
|
|
|
|
shrinkWrap: true,
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
itemCount:
|
|
|
|
controller.filteredHomeservers.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
final server =
|
|
|
|
controller.filteredHomeservers[index];
|
|
|
|
return HomeserverTile(
|
|
|
|
server: server, controller: controller);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-04-15 14:31:57 +02:00
|
|
|
),
|
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
Wrap(
|
|
|
|
alignment: WrapAlignment.center,
|
|
|
|
children: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => launch(AppConfig.privacyUrl),
|
|
|
|
child: Text(
|
|
|
|
L10n.of(context)!.privacy,
|
|
|
|
style: const TextStyle(
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
color: Colors.white,
|
2021-06-11 10:08:04 +02:00
|
|
|
),
|
|
|
|
),
|
2021-11-15 12:14:00 +01:00
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
TextButton(
|
|
|
|
onPressed: () => PlatformInfos.showDialog(context),
|
|
|
|
child: Text(
|
|
|
|
L10n.of(context)!.about,
|
|
|
|
style: const TextStyle(
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
color: Colors.white,
|
2021-11-15 12:14:00 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
],
|
2021-04-09 16:28:26 +02:00
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
],
|
2021-11-20 11:03:42 +01:00
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
child: Hero(
|
|
|
|
tag: 'loginButton',
|
|
|
|
child: ElevatedButton(
|
|
|
|
onPressed: controller.isLoading
|
|
|
|
? () {}
|
|
|
|
: controller.checkHomeserverAction,
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
primary: Colors.white.withAlpha(200),
|
|
|
|
onPrimary: Colors.black,
|
|
|
|
shadowColor: Colors.white,
|
|
|
|
),
|
|
|
|
child: controller.isLoading
|
|
|
|
? const LinearProgressIndicator()
|
|
|
|
: Text(L10n.of(context)!.connect),
|
2021-11-15 09:48:21 +01:00
|
|
|
),
|
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
),
|
|
|
|
],
|
2021-04-09 16:28:26 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|