fluffychat/lib/pages/views/sign_up_view.dart

178 lines
7.2 KiB
Dart
Raw Normal View History

2021-01-16 12:46:38 +01:00
import 'package:adaptive_page_layout/adaptive_page_layout.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-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,
2021-04-12 17:31:53 +02:00
leading: controller.loading ? Container() : BackButton(),
2021-04-09 14:56:23 +02:00
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(),
),
SizedBox(height: 16),
if (controller.passwordLoginSupported) ...{
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: TextField(
readOnly: controller.loading,
autocorrect: false,
controller: controller.usernameController,
onSubmitted: controller.signUpAction,
autofillHints: controller.loading
? null
: [AutofillHints.newUsername],
decoration: InputDecoration(
prefixIcon: Icon(Icons.account_circle_outlined),
hintText: L10n.of(context).username,
errorText: controller.usernameError,
labelText: L10n.of(context).chooseAUsername,
2021-04-09 14:56:23 +02:00
),
2021-05-22 10:25:37 +02:00
),
),
SizedBox(height: 8),
ListTile(
leading: CircleAvatar(
backgroundImage: controller.avatar == null
? null
: MemoryImage(controller.avatar.bytes),
backgroundColor: controller.avatar == null
? Theme.of(context).brightness == Brightness.dark
? Color(0xff121212)
: Colors.white
: Theme.of(context).secondaryHeaderColor,
child: controller.avatar == null
? Icon(Icons.camera_alt_outlined,
color: Theme.of(context).primaryColor)
: null,
),
trailing: controller.avatar == null
? null
: Icon(
Icons.close,
color: Colors.red,
),
title: Text(controller.avatar == null
? L10n.of(context).setAProfilePicture
: L10n.of(context).discardPicture),
onTap: controller.avatar == null
? controller.setAvatarAction
: controller.resetAvatarAction,
),
SizedBox(height: 16),
Hero(
tag: 'loginButton',
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 12),
child: ElevatedButton(
onPressed:
controller.loading ? null : controller.signUpAction,
child: controller.loading
? LinearProgressIndicator()
: Text(
L10n.of(context).signUp.toUpperCase(),
style: TextStyle(
color: Colors.white, fontSize: 16),
),
),
),
),
Row(
children: [
Expanded(
child: Container(
height: 1,
color: Theme.of(context).dividerColor,
)),
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(L10n.of(context).or),
),
Expanded(
child: Container(
height: 1,
color: Theme.of(context).dividerColor,
)),
],
),
},
Padding(
padding: EdgeInsets.symmetric(horizontal: 12),
child: Row(children: [
if (controller.passwordLoginSupported)
Expanded(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).secondaryHeaderColor,
onPrimary:
Theme.of(context).textTheme.bodyText1.color,
elevation: 2,
),
onPressed: () => AdaptivePageLayout.of(context)
.pushNamed('/login'),
child: Text(L10n.of(context).login),
),
),
if (controller.passwordLoginSupported &&
controller.ssoLoginSupported)
SizedBox(width: 12),
if (controller.ssoLoginSupported)
Expanded(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).secondaryHeaderColor,
onPrimary:
Theme.of(context).textTheme.bodyText1.color,
elevation: 2,
),
onPressed: controller.ssoLoginAction,
child: Text(L10n.of(context).useSSO),
),
),
]),
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
);
}
}