feat: New simplified login process with more prominent SSO and nicer layout
parent
865cbe9618
commit
bcf0d5e238
Binary file not shown.
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 44 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 212 KiB After Width: | Height: | Size: 146 KiB |
@ -1,197 +0,0 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:flutter_web_auth_2/flutter_web_auth_2.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:universal_html/html.dart' as html;
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pages/connect/connect_page_view.dart';
|
||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class ConnectPage extends StatefulWidget {
|
||||
const ConnectPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ConnectPage> createState() => ConnectPageController();
|
||||
}
|
||||
|
||||
class ConnectPageController extends State<ConnectPage> {
|
||||
final TextEditingController usernameController = TextEditingController();
|
||||
String? signupError;
|
||||
bool loading = false;
|
||||
|
||||
void pickAvatar() async {
|
||||
final source = !PlatformInfos.isMobile
|
||||
? ImageSource.gallery
|
||||
: await showModalActionSheet<ImageSource>(
|
||||
context: context,
|
||||
title: L10n.of(context)!.changeYourAvatar,
|
||||
actions: [
|
||||
SheetAction(
|
||||
key: ImageSource.camera,
|
||||
label: L10n.of(context)!.openCamera,
|
||||
isDefaultAction: true,
|
||||
icon: Icons.camera_alt_outlined,
|
||||
),
|
||||
SheetAction(
|
||||
key: ImageSource.gallery,
|
||||
label: L10n.of(context)!.openGallery,
|
||||
icon: Icons.photo_outlined,
|
||||
),
|
||||
],
|
||||
);
|
||||
if (source == null) return;
|
||||
final picked = await ImagePicker().pickImage(
|
||||
source: source,
|
||||
imageQuality: 50,
|
||||
maxWidth: 512,
|
||||
maxHeight: 512,
|
||||
);
|
||||
setState(() {
|
||||
Matrix.of(context).loginAvatar = picked;
|
||||
});
|
||||
}
|
||||
|
||||
void signUp() async {
|
||||
usernameController.text = usernameController.text.trim();
|
||||
final localpart =
|
||||
usernameController.text.toLowerCase().replaceAll(' ', '_');
|
||||
if (localpart.isEmpty) {
|
||||
setState(() {
|
||||
signupError = L10n.of(context)!.pleaseChooseAUsername;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
signupError = null;
|
||||
loading = true;
|
||||
});
|
||||
|
||||
try {
|
||||
try {
|
||||
await Matrix.of(context).getLoginClient().register(username: localpart);
|
||||
} on MatrixException catch (e) {
|
||||
if (!e.requireAdditionalAuthentication) rethrow;
|
||||
}
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
Matrix.of(context).loginUsername = usernameController.text;
|
||||
VRouter.of(context).to('signup');
|
||||
} catch (e, s) {
|
||||
Logs().d('Sign up failed', e, s);
|
||||
setState(() {
|
||||
signupError = e.toLocalizedString(context);
|
||||
loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
bool _supportsFlow(String flowType) =>
|
||||
Matrix.of(context)
|
||||
.loginHomeserverSummary
|
||||
?.loginFlows
|
||||
.any((flow) => flow.type == flowType) ??
|
||||
false;
|
||||
|
||||
bool get supportsSso => _supportsFlow('m.login.sso');
|
||||
|
||||
bool isDefaultPlatform =
|
||||
(PlatformInfos.isMobile || PlatformInfos.isWeb || PlatformInfos.isMacOS);
|
||||
|
||||
bool get supportsLogin => _supportsFlow('m.login.password');
|
||||
|
||||
void login() => VRouter.of(context).to('login');
|
||||
|
||||
Map<String, dynamic>? _rawLoginTypes;
|
||||
|
||||
List<IdentityProvider>? get identityProviders {
|
||||
final loginTypes = _rawLoginTypes;
|
||||
if (loginTypes == null) return null;
|
||||
final rawProviders = loginTypes.tryGetList('flows')!.singleWhere(
|
||||
(flow) => flow['type'] == AuthenticationTypes.sso,
|
||||
)['identity_providers'];
|
||||
final list = (rawProviders as List)
|
||||
.map((json) => IdentityProvider.fromJson(json))
|
||||
.toList();
|
||||
if (PlatformInfos.isCupertinoStyle) {
|
||||
list.sort((a, b) => a.brand == 'apple' ? -1 : 1);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
void ssoLoginAction(String id) async {
|
||||
final redirectUrl = kIsWeb
|
||||
? '${html.window.origin!}/web/auth.html'
|
||||
: isDefaultPlatform
|
||||
? '${AppConfig.appOpenUrlScheme.toLowerCase()}://login'
|
||||
: 'http://localhost:3001//login';
|
||||
final url =
|
||||
'${Matrix.of(context).getLoginClient().homeserver?.toString()}/_matrix/client/r0/login/sso/redirect/${Uri.encodeComponent(id)}?redirectUrl=${Uri.encodeQueryComponent(redirectUrl)}';
|
||||
final urlScheme = isDefaultPlatform
|
||||
? Uri.parse(redirectUrl).scheme
|
||||
: "http://localhost:3001";
|
||||
final result = await FlutterWebAuth2.authenticate(
|
||||
url: url,
|
||||
callbackUrlScheme: urlScheme,
|
||||
);
|
||||
final token = Uri.parse(result).queryParameters['loginToken'];
|
||||
if (token?.isEmpty ?? false) return;
|
||||
|
||||
await showFutureLoadingDialog(
|
||||
context: context,
|
||||
future: () => Matrix.of(context).getLoginClient().login(
|
||||
LoginType.mLoginToken,
|
||||
token: token,
|
||||
initialDeviceDisplayName: PlatformInfos.clientName,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (supportsSso) {
|
||||
Matrix.of(context)
|
||||
.getLoginClient()
|
||||
.request(
|
||||
RequestType.GET,
|
||||
'/client/r0/login',
|
||||
)
|
||||
.then(
|
||||
(loginTypes) => setState(() {
|
||||
_rawLoginTypes = loginTypes;
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ConnectPageView(this);
|
||||
}
|
||||
|
||||
class IdentityProvider {
|
||||
final String? id;
|
||||
final String? name;
|
||||
final String? icon;
|
||||
final String? brand;
|
||||
|
||||
IdentityProvider({this.id, this.name, this.icon, this.brand});
|
||||
|
||||
factory IdentityProvider.fromJson(Map<String, dynamic> json) =>
|
||||
IdentityProvider(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
icon: json['icon'],
|
||||
brand: json['brand'],
|
||||
);
|
||||
}
|
||||
@ -1,226 +0,0 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pages/connect/connect_page.dart';
|
||||
import 'package:fluffychat/widgets/layouts/login_scaffold.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'sso_button.dart';
|
||||
|
||||
class ConnectPageView extends StatelessWidget {
|
||||
final ConnectPageController controller;
|
||||
const ConnectPageView(this.controller, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final avatar = Matrix.of(context).loginAvatar;
|
||||
final identityProviders = controller.identityProviders;
|
||||
return LoginScaffold(
|
||||
appBar: AppBar(
|
||||
leading: controller.loading ? null : const BackButton(),
|
||||
automaticallyImplyLeading: !controller.loading,
|
||||
centerTitle: true,
|
||||
title: Text(
|
||||
Matrix.of(context).getLoginClient().homeserver?.host ?? '',
|
||||
),
|
||||
),
|
||||
body: ListView(
|
||||
key: const Key('ConnectPageListView'),
|
||||
children: [
|
||||
if (Matrix.of(context).loginRegistrationSupported ?? false) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Center(
|
||||
child: Stack(
|
||||
children: [
|
||||
Material(
|
||||
borderRadius: BorderRadius.circular(64),
|
||||
elevation: Theme.of(context)
|
||||
.appBarTheme
|
||||
.scrolledUnderElevation ??
|
||||
10,
|
||||
color: Colors.transparent,
|
||||
shadowColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.onBackground
|
||||
.withAlpha(64),
|
||||
clipBehavior: Clip.hardEdge,
|
||||
child: CircleAvatar(
|
||||
radius: 64,
|
||||
backgroundColor: Colors.white,
|
||||
child: avatar == null
|
||||
? const Icon(
|
||||
Icons.person,
|
||||
color: Colors.black,
|
||||
size: 64,
|
||||
)
|
||||
: FutureBuilder<Uint8List>(
|
||||
future: avatar.readAsBytes(),
|
||||
builder: (context, snapshot) {
|
||||
final bytes = snapshot.data;
|
||||
if (bytes == null) {
|
||||
return const CircularProgressIndicator
|
||||
.adaptive();
|
||||
}
|
||||
return Image.memory(
|
||||
bytes,
|
||||
fit: BoxFit.cover,
|
||||
width: 128,
|
||||
height: 128,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
child: FloatingActionButton(
|
||||
mini: true,
|
||||
onPressed: controller.pickAvatar,
|
||||
backgroundColor: Colors.white,
|
||||
foregroundColor: Colors.black,
|
||||
child: const Icon(Icons.camera_alt_outlined),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: TextField(
|
||||
controller: controller.usernameController,
|
||||
onSubmitted: (_) => controller.signUp(),
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.account_box_outlined),
|
||||
hintText: L10n.of(context)!.chooseAUsername,
|
||||
errorText: controller.signupError,
|
||||
errorStyle: const TextStyle(color: Colors.orange),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Hero(
|
||||
tag: 'loginButton',
|
||||
child: ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
foregroundColor: Theme.of(context).colorScheme.onPrimary,
|
||||
),
|
||||
onPressed: controller.loading ? () {} : controller.signUp,
|
||||
icon: const Icon(Icons.person_add_outlined),
|
||||
label: controller.loading
|
||||
? const LinearProgressIndicator()
|
||||
: Text(L10n.of(context)!.signUp),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Divider(
|
||||
thickness: 1,
|
||||
color: Theme.of(context).dividerColor,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Text(
|
||||
L10n.of(context)!.or,
|
||||
style: const TextStyle(fontSize: 18),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Divider(
|
||||
thickness: 1,
|
||||
color: Theme.of(context).dividerColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
if (controller.supportsSso)
|
||||
identityProviders == null
|
||||
? const SizedBox(
|
||||
height: 74,
|
||||
child: Center(child: CircularProgressIndicator.adaptive()),
|
||||
)
|
||||
: Center(
|
||||
child: identityProviders.length == 1
|
||||
? Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.primaryContainer,
|
||||
foregroundColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimaryContainer,
|
||||
),
|
||||
icon: identityProviders.single.icon == null
|
||||
? const Icon(
|
||||
Icons.web_outlined,
|
||||
size: 16,
|
||||
)
|
||||
: Image.network(
|
||||
Uri.parse(identityProviders.single.icon!)
|
||||
.getDownloadLink(
|
||||
Matrix.of(context).getLoginClient(),
|
||||
)
|
||||
.toString(),
|
||||
width: 32,
|
||||
height: 32,
|
||||
),
|
||||
onPressed: () => controller
|
||||
.ssoLoginAction(identityProviders.single.id!),
|
||||
label: Text(
|
||||
identityProviders.single.name ??
|
||||
identityProviders.single.brand ??
|
||||
L10n.of(context)!.loginWithOneClick,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Wrap(
|
||||
children: [
|
||||
for (final identityProvider in identityProviders)
|
||||
SsoButton(
|
||||
onPressed: () => controller
|
||||
.ssoLoginAction(identityProvider.id!),
|
||||
identityProvider: identityProvider,
|
||||
),
|
||||
].toList(),
|
||||
),
|
||||
),
|
||||
if (controller.supportsLogin)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Hero(
|
||||
tag: 'signinButton',
|
||||
child: ElevatedButton.icon(
|
||||
icon: const Icon(Icons.login_outlined),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor:
|
||||
Theme.of(context).colorScheme.primaryContainer,
|
||||
foregroundColor:
|
||||
Theme.of(context).colorScheme.onPrimaryContainer,
|
||||
),
|
||||
onPressed: controller.loading ? () {} : controller.login,
|
||||
label: Text(L10n.of(context)!.login),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,63 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'package:fluffychat/pages/connect/connect_page.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class SsoButton extends StatelessWidget {
|
||||
final IdentityProvider identityProvider;
|
||||
final void Function()? onPressed;
|
||||
const SsoButton({
|
||||
Key? key,
|
||||
required this.identityProvider,
|
||||
this.onPressed,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: onPressed,
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Material(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
clipBehavior: Clip.hardEdge,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
child: identityProvider.icon == null
|
||||
? const Icon(Icons.web_outlined)
|
||||
: Image.network(
|
||||
Uri.parse(identityProvider.icon!)
|
||||
.getDownloadLink(
|
||||
Matrix.of(context).getLoginClient(),
|
||||
)
|
||||
.toString(),
|
||||
width: 32,
|
||||
height: 32,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
identityProvider.name ??
|
||||
identityProvider.brand ??
|
||||
L10n.of(context)!.singlesignon,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,129 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:vrouter/vrouter.dart';
|
||||
|
||||
import 'package:fluffychat/pages/sign_up/signup_view.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import '../../utils/localized_exception_extension.dart';
|
||||
|
||||
class SignupPage extends StatefulWidget {
|
||||
const SignupPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
SignupPageController createState() => SignupPageController();
|
||||
}
|
||||
|
||||
class SignupPageController extends State<SignupPage> {
|
||||
final TextEditingController passwordController = TextEditingController();
|
||||
final TextEditingController password2Controller = TextEditingController();
|
||||
final TextEditingController emailController = TextEditingController();
|
||||
String? error;
|
||||
bool loading = false;
|
||||
bool showPassword = false;
|
||||
bool noEmailWarningConfirmed = false;
|
||||
bool displaySecondPasswordField = false;
|
||||
|
||||
static const int minPassLength = 8;
|
||||
|
||||
void toggleShowPassword() => setState(() => showPassword = !showPassword);
|
||||
|
||||
String? get domain => VRouter.of(context).queryParameters['domain'];
|
||||
|
||||
final GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||
|
||||
void onPasswordType(String text) {
|
||||
if (text.length >= minPassLength && !displaySecondPasswordField) {
|
||||
setState(() {
|
||||
displaySecondPasswordField = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
String? password1TextFieldValidator(String? value) {
|
||||
if (value!.isEmpty) {
|
||||
return L10n.of(context)!.chooseAStrongPassword;
|
||||
}
|
||||
if (value.length < minPassLength) {
|
||||
return L10n.of(context)!
|
||||
.pleaseChooseAtLeastChars(minPassLength.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String? password2TextFieldValidator(String? value) {
|
||||
if (value!.isEmpty) {
|
||||
return L10n.of(context)!.repeatPassword;
|
||||
}
|
||||
if (value != passwordController.text) {
|
||||
return L10n.of(context)!.passwordsDoNotMatch;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String? emailTextFieldValidator(String? value) {
|
||||
if (value!.isEmpty && !noEmailWarningConfirmed) {
|
||||
noEmailWarningConfirmed = true;
|
||||
return L10n.of(context)!.noEmailWarning;
|
||||
}
|
||||
if (value.isNotEmpty && !value.contains('@')) {
|
||||
return L10n.of(context)!.pleaseEnterValidEmail;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void signup([_]) async {
|
||||
setState(() {
|
||||
error = null;
|
||||
});
|
||||
if (!formKey.currentState!.validate()) return;
|
||||
|
||||
setState(() {
|
||||
loading = true;
|
||||
});
|
||||
|
||||
try {
|
||||
final client = Matrix.of(context).getLoginClient();
|
||||
final email = emailController.text;
|
||||
if (email.isNotEmpty) {
|
||||
Matrix.of(context).currentClientSecret =
|
||||
DateTime.now().millisecondsSinceEpoch.toString();
|
||||
Matrix.of(context).currentThreepidCreds =
|
||||
await client.requestTokenToRegisterEmail(
|
||||
Matrix.of(context).currentClientSecret,
|
||||
email,
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
final displayname = Matrix.of(context).loginUsername!;
|
||||
final localPart = displayname.toLowerCase().replaceAll(' ', '_');
|
||||
|
||||
await client.uiaRequestBackground(
|
||||
(auth) => client.register(
|
||||
username: localPart,
|
||||
password: passwordController.text,
|
||||
initialDeviceDisplayName: PlatformInfos.clientName,
|
||||
auth: auth,
|
||||
),
|
||||
);
|
||||
// Set displayname
|
||||
if (displayname != localPart) {
|
||||
await client.setDisplayName(
|
||||
client.userID!,
|
||||
displayname,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
error = (e).toLocalizedString(context);
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() => loading = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SignupPageView(this);
|
||||
}
|
||||
@ -1,115 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import 'package:fluffychat/widgets/layouts/login_scaffold.dart';
|
||||
import 'signup.dart';
|
||||
|
||||
class SignupPageView extends StatelessWidget {
|
||||
final SignupPageController controller;
|
||||
const SignupPageView(this.controller, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LoginScaffold(
|
||||
appBar: AppBar(
|
||||
leading: controller.loading ? null : const BackButton(),
|
||||
automaticallyImplyLeading: !controller.loading,
|
||||
title: Text(L10n.of(context)!.signUp),
|
||||
),
|
||||
body: Form(
|
||||
key: controller.formKey,
|
||||
child: ListView(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: TextFormField(
|
||||
readOnly: controller.loading,
|
||||
autocorrect: false,
|
||||
onChanged: controller.onPasswordType,
|
||||
autofillHints:
|
||||
controller.loading ? null : [AutofillHints.newPassword],
|
||||
controller: controller.passwordController,
|
||||
obscureText: !controller.showPassword,
|
||||
validator: controller.password1TextFieldValidator,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.vpn_key_outlined),
|
||||
suffixIcon: IconButton(
|
||||
tooltip: L10n.of(context)!.showPassword,
|
||||
icon: Icon(
|
||||
controller.showPassword
|
||||
? Icons.visibility_off_outlined
|
||||
: Icons.visibility_outlined,
|
||||
color: Colors.black,
|
||||
),
|
||||
onPressed: controller.toggleShowPassword,
|
||||
),
|
||||
errorStyle: const TextStyle(color: Colors.orange),
|
||||
hintText: L10n.of(context)!.chooseAStrongPassword,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (controller.displaySecondPasswordField)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: TextFormField(
|
||||
readOnly: controller.loading,
|
||||
autocorrect: false,
|
||||
autofillHints:
|
||||
controller.loading ? null : [AutofillHints.newPassword],
|
||||
controller: controller.password2Controller,
|
||||
obscureText: !controller.showPassword,
|
||||
validator: controller.password2TextFieldValidator,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.repeat_outlined),
|
||||
hintText: L10n.of(context)!.repeatPassword,
|
||||
errorStyle: const TextStyle(color: Colors.orange),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: TextFormField(
|
||||
readOnly: controller.loading,
|
||||
autocorrect: false,
|
||||
controller: controller.emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
autofillHints:
|
||||
controller.loading ? null : [AutofillHints.username],
|
||||
validator: controller.emailTextFieldValidator,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.mail_outlined),
|
||||
hintText: L10n.of(context)!.enterAnEmailAddress,
|
||||
errorText: controller.error,
|
||||
errorMaxLines: 4,
|
||||
errorStyle: TextStyle(
|
||||
color: controller.emailController.text.isEmpty
|
||||
? Colors.orangeAccent
|
||||
: Colors.orange,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Hero(
|
||||
tag: 'loginButton',
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: ElevatedButton.icon(
|
||||
icon: const Icon(Icons.person_add_outlined),
|
||||
style: ElevatedButton.styleFrom(
|
||||
foregroundColor: Theme.of(context).colorScheme.onPrimary,
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
onPressed: controller.loading ? () {} : controller.signup,
|
||||
label: controller.loading
|
||||
? const LinearProgressIndicator()
|
||||
: Text(L10n.of(context)!.signUp),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue