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';
|
2020-10-03 13:11:07 +02:00
|
|
|
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(
|
2021-05-23 13:11:55 +02:00
|
|
|
backgroundImage: SignUpController.avatar == null
|
2021-05-22 10:25:37 +02:00
|
|
|
? null
|
2021-05-23 13:11:55 +02:00
|
|
|
: MemoryImage(SignUpController.avatar.bytes),
|
|
|
|
backgroundColor: SignUpController.avatar == null
|
2021-05-22 10:25:37 +02:00
|
|
|
? Theme.of(context).brightness == Brightness.dark
|
|
|
|
? Color(0xff121212)
|
|
|
|
: Colors.white
|
|
|
|
: Theme.of(context).secondaryHeaderColor,
|
2021-05-23 13:11:55 +02:00
|
|
|
child: SignUpController.avatar == null
|
2021-05-22 10:25:37 +02:00
|
|
|
? Icon(Icons.camera_alt_outlined,
|
|
|
|
color: Theme.of(context).primaryColor)
|
|
|
|
: null,
|
|
|
|
),
|
2021-05-23 13:11:55 +02:00
|
|
|
trailing: SignUpController.avatar == null
|
2021-05-22 10:25:37 +02:00
|
|
|
? null
|
|
|
|
: Icon(
|
|
|
|
Icons.close,
|
|
|
|
color: Colors.red,
|
|
|
|
),
|
2021-05-23 13:11:55 +02:00
|
|
|
title: Text(SignUpController.avatar == null
|
2021-05-22 10:25:37 +02:00
|
|
|
? L10n.of(context).setAProfilePicture
|
|
|
|
: L10n.of(context).discardPicture),
|
2021-05-23 13:11:55 +02:00
|
|
|
onTap: SignUpController.avatar == null
|
2021-05-22 10:25:37 +02:00
|
|
|
? 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,
|
|
|
|
),
|
2021-05-23 13:11:55 +02:00
|
|
|
onPressed: () => context.vRouter.push('/login'),
|
2021-05-22 10:25:37 +02:00
|
|
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|