2021-05-22 09:08:23 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
|
2021-05-22 09:08:23 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
|
2022-04-15 11:42:59 +02:00
|
|
|
import 'package:fluffychat/widgets/layouts/login_scaffold.dart';
|
2021-10-26 18:50:34 +02:00
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
2021-11-09 21:32:16 +01:00
|
|
|
import 'login.dart';
|
2021-05-22 09:08:23 +02:00
|
|
|
|
|
|
|
class LoginView extends StatelessWidget {
|
|
|
|
final LoginController controller;
|
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
const LoginView(this.controller, {Key? key}) : super(key: key);
|
2021-05-22 09:08:23 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-04-15 11:42:59 +02:00
|
|
|
return LoginScaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
automaticallyImplyLeading: !controller.loading,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
iconTheme: const IconThemeData(color: Colors.white),
|
|
|
|
elevation: 0,
|
|
|
|
centerTitle: true,
|
|
|
|
title: Text(
|
|
|
|
L10n.of(context)!.logInTo(Matrix.of(context)
|
|
|
|
.getLoginClient()
|
|
|
|
.homeserver
|
|
|
|
.toString()
|
|
|
|
.replaceFirst('https://', '')),
|
|
|
|
style: const TextStyle(color: Colors.white),
|
2021-05-22 09:08:23 +02:00
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
),
|
|
|
|
body: Builder(builder: (context) {
|
|
|
|
return AutofillGroup(
|
|
|
|
child: ListView(
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
2022-08-05 21:04:37 +02:00
|
|
|
padding: const EdgeInsets.all(12.0),
|
2022-04-15 11:42:59 +02:00
|
|
|
child: TextField(
|
|
|
|
readOnly: controller.loading,
|
|
|
|
autocorrect: false,
|
|
|
|
autofocus: true,
|
|
|
|
onChanged: controller.checkWellKnownWithCoolDown,
|
|
|
|
controller: controller.usernameController,
|
|
|
|
textInputAction: TextInputAction.next,
|
|
|
|
keyboardType: TextInputType.emailAddress,
|
|
|
|
autofillHints:
|
|
|
|
controller.loading ? null : [AutofillHints.username],
|
2022-07-07 18:50:13 +02:00
|
|
|
decoration: InputDecoration(
|
|
|
|
prefixIcon: const Icon(Icons.account_box_outlined),
|
2022-04-15 11:42:59 +02:00
|
|
|
errorText: controller.usernameError,
|
|
|
|
hintText: L10n.of(context)!.emailOrUsername,
|
2022-07-07 18:50:13 +02:00
|
|
|
fillColor: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.background
|
|
|
|
.withOpacity(0.75),
|
2021-05-30 12:25:29 +02:00
|
|
|
),
|
2021-05-22 09:08:23 +02:00
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
),
|
|
|
|
Padding(
|
2022-08-05 21:04:37 +02:00
|
|
|
padding: const EdgeInsets.all(12.0),
|
2022-04-15 11:42:59 +02:00
|
|
|
child: TextField(
|
|
|
|
readOnly: controller.loading,
|
|
|
|
autocorrect: false,
|
|
|
|
autofillHints:
|
|
|
|
controller.loading ? null : [AutofillHints.password],
|
|
|
|
controller: controller.passwordController,
|
|
|
|
textInputAction: TextInputAction.next,
|
|
|
|
obscureText: !controller.showPassword,
|
|
|
|
onSubmitted: controller.login,
|
2022-07-07 18:50:13 +02:00
|
|
|
decoration: InputDecoration(
|
|
|
|
prefixIcon: const Icon(Icons.lock_outlined),
|
2022-04-15 11:42:59 +02:00
|
|
|
errorText: controller.passwordError,
|
|
|
|
suffixIcon: IconButton(
|
|
|
|
tooltip: L10n.of(context)!.showPassword,
|
2022-04-24 07:57:08 +02:00
|
|
|
icon: Icon(
|
|
|
|
controller.showPassword
|
|
|
|
? Icons.visibility_off_outlined
|
|
|
|
: Icons.visibility_outlined,
|
|
|
|
color: Colors.black,
|
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
onPressed: controller.toggleShowPassword,
|
2021-08-08 19:30:51 +02:00
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
hintText: L10n.of(context)!.password,
|
2022-07-07 18:50:13 +02:00
|
|
|
fillColor: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.background
|
|
|
|
.withOpacity(0.75),
|
2021-05-22 09:08:23 +02:00
|
|
|
),
|
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
),
|
|
|
|
Hero(
|
|
|
|
tag: 'signinButton',
|
|
|
|
child: Padding(
|
2022-08-05 21:04:37 +02:00
|
|
|
padding: const EdgeInsets.all(12.0),
|
2022-02-19 13:11:59 +01:00
|
|
|
child: ElevatedButton(
|
|
|
|
onPressed: controller.loading
|
|
|
|
? null
|
2022-04-15 11:42:59 +02:00
|
|
|
: () => controller.login(context),
|
|
|
|
child: controller.loading
|
|
|
|
? const LinearProgressIndicator()
|
|
|
|
: Text(L10n.of(context)!.login),
|
2021-05-22 09:08:23 +02:00
|
|
|
),
|
|
|
|
),
|
2022-04-15 11:42:59 +02:00
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
const Expanded(child: Divider(color: Colors.white)),
|
|
|
|
Padding(
|
2022-08-05 21:04:37 +02:00
|
|
|
padding: const EdgeInsets.all(12.0),
|
2022-04-15 11:42:59 +02:00
|
|
|
child: Text(
|
|
|
|
L10n.of(context)!.or,
|
|
|
|
style: const TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const Expanded(child: Divider(color: Colors.white)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Padding(
|
2022-08-05 21:04:37 +02:00
|
|
|
padding: const EdgeInsets.all(12.0),
|
2022-04-15 11:42:59 +02:00
|
|
|
child: ElevatedButton(
|
|
|
|
onPressed:
|
|
|
|
controller.loading ? () {} : controller.passwordForgotten,
|
2022-07-07 18:50:13 +02:00
|
|
|
style: ElevatedButton.styleFrom(onPrimary: Colors.red),
|
2022-04-15 11:42:59 +02:00
|
|
|
child: Text(L10n.of(context)!.passwordForgotten),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
2021-05-22 09:08:23 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|