fluffychat/lib/pages/views/sign_up_view.dart

137 lines
5.5 KiB
Dart
Raw Normal View History

2021-06-06 16:55:31 +02:00
import 'package:cached_network_image/cached_network_image.dart';
2021-05-23 13:11:55 +02:00
import 'package:vrouter/vrouter.dart';
2021-05-22 08:57:49 +02:00
import 'package:fluffychat/pages/sign_up.dart';
2021-05-22 08:53:52 +02:00
import 'package:fluffychat/widgets/fluffy_banner.dart';
2020-10-04 17:01:54 +02:00
2021-05-22 08:53:52 +02:00
import 'package:fluffychat/widgets/matrix.dart';
import 'package:fluffychat/widgets/layouts/one_page_card.dart';
2020-01-09 22:52:27 +01:00
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-05-22 10:25:37 +02:00
import '../../utils/localized_exception_extension.dart';
2020-01-09 22:52:27 +01:00
2021-06-06 16:55:31 +02:00
import 'package:famedlysdk/famedlysdk.dart';
2021-05-22 09:13:47 +02:00
class SignUpView extends StatelessWidget {
2021-04-12 17:31:53 +02:00
final SignUpController controller;
2020-01-09 22:52:27 +01:00
2021-05-22 09:13:47 +02:00
const SignUpView(this.controller, {Key key}) : super(key: key);
2020-01-09 22:52:27 +01:00
@override
Widget build(BuildContext context) {
2021-04-09 14:56:23 +02:00
return OnePageCard(
child: Scaffold(
appBar: AppBar(
elevation: 0,
title: Text(
Matrix.of(context)
.client
.homeserver
.toString()
.replaceFirst('https://', ''),
),
2020-01-09 22:52:27 +01:00
),
2021-05-22 10:25:37 +02:00
body: FutureBuilder(
future: controller.getLoginTypes(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return Center(
child: Text(
snapshot.error.toLocalizedString(context),
textAlign: TextAlign.center,
2021-04-09 14:56:23 +02:00
),
2021-05-22 10:25:37 +02:00
);
}
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
}
return ListView(children: <Widget>[
Hero(
tag: 'loginBanner',
child: FluffyBanner(),
),
Padding(
2021-06-06 16:55:31 +02:00
padding: const EdgeInsets.all(12.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (controller.ssoLoginSupported) ...{
for (final identityProvider
in controller.identityProviders)
OutlinedButton.icon(
onPressed: () =>
controller.ssoLoginAction(identityProvider.id),
icon: identityProvider.icon == null
? Icon(Icons.web_outlined)
: CachedNetworkImage(
imageUrl: Uri.parse(identityProvider.icon)
.getDownloadLink(
Matrix.of(context).client)
.toString(),
width: 24,
height: 24,
),
label: Text(L10n.of(context).loginWith(
identityProvider.brand ??
identityProvider.name ??
L10n.of(context).singlesignon)),
2021-05-22 10:25:37 +02:00
),
2021-06-06 16:55:31 +02:00
if (controller.registrationSupported ||
controller.passwordLoginSupported)
Row(children: [
Expanded(child: Divider()),
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(L10n.of(context).or),
),
Expanded(child: Divider()),
]),
},
Row(
children: [
if (controller.passwordLoginSupported)
Expanded(
child: Container(
height: 64,
child: OutlinedButton.icon(
onPressed: () =>
context.vRouter.push('/login'),
icon: Icon(Icons.login_outlined),
label: Text(L10n.of(context).login),
),
),
),
if (controller.registrationSupported &&
controller.passwordLoginSupported)
SizedBox(width: 12),
if (controller.registrationSupported)
Expanded(
child: Container(
height: 64,
child: OutlinedButton.icon(
onPressed: controller.signUpAction,
icon: Icon(Icons.add_box_outlined),
label: Text(L10n.of(context).register),
),
),
),
],
2021-05-22 10:25:37 +02:00
),
2021-06-06 16:55:31 +02:00
]
.map(
(widget) => Container(
height: 64,
padding: EdgeInsets.only(bottom: 12),
child: widget),
)
.toList(),
),
2020-01-09 22:52:27 +01:00
),
2021-05-22 10:25:37 +02:00
]);
}),
2021-04-09 14:56:23 +02:00
),
2020-01-09 22:52:27 +01:00
);
}
}