2021-05-22 07:08:23 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
|
2021-05-22 07:08:23 +00:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
|
2022-04-15 09:42:59 +00:00
|
|
|
import 'package:fluffychat/widgets/layouts/login_scaffold.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
2021-11-09 20:32:16 +00:00
|
|
|
import 'login.dart';
|
2021-05-22 07:08:23 +00:00
|
|
|
|
|
|
|
class LoginView extends StatelessWidget {
|
|
|
|
final LoginController controller;
|
|
|
|
|
2023-10-28 11:03:16 +00:00
|
|
|
const LoginView(this.controller, {super.key});
|
2021-05-22 07:08:23 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-08-04 12:09:36 +00:00
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
2023-12-24 12:46:29 +00:00
|
|
|
final homeserver = Matrix.of(context)
|
|
|
|
.getLoginClient()
|
|
|
|
.homeserver
|
|
|
|
.toString()
|
|
|
|
.replaceFirst('https://', '');
|
|
|
|
final title = L10n.of(context)!.logInTo(homeserver);
|
|
|
|
final titleParts = title.split(homeserver);
|
|
|
|
|
2022-04-15 09:42:59 +00:00
|
|
|
return LoginScaffold(
|
2023-09-22 06:26:43 +00:00
|
|
|
enforceMobileMode: Matrix.of(context).client.isLogged(),
|
2022-04-15 09:42:59 +00:00
|
|
|
appBar: AppBar(
|
2023-12-24 12:46:29 +00:00
|
|
|
leading: controller.loading ? null : const Center(child: BackButton()),
|
2022-04-15 09:42:59 +00:00
|
|
|
automaticallyImplyLeading: !controller.loading,
|
2023-12-24 12:46:29 +00:00
|
|
|
titleSpacing: !controller.loading ? 0 : null,
|
|
|
|
title: Text.rich(
|
|
|
|
TextSpan(
|
|
|
|
children: [
|
|
|
|
TextSpan(text: titleParts.first),
|
|
|
|
TextSpan(
|
|
|
|
text: homeserver,
|
|
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
TextSpan(text: titleParts.last),
|
|
|
|
],
|
2023-03-02 09:57:52 +00:00
|
|
|
),
|
2023-12-24 12:46:29 +00:00
|
|
|
style: const TextStyle(fontSize: 18),
|
2021-05-22 07:08:23 +00:00
|
|
|
),
|
2022-04-15 09:42:59 +00:00
|
|
|
),
|
2023-03-02 09:57:52 +00:00
|
|
|
body: Builder(
|
|
|
|
builder: (context) {
|
|
|
|
return AutofillGroup(
|
|
|
|
child: ListView(
|
2023-12-24 12:46:29 +00:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
2023-03-02 09:57:52 +00:00
|
|
|
children: <Widget>[
|
2023-12-24 12:46:29 +00:00
|
|
|
Image.asset('assets/banner_transparent.png'),
|
|
|
|
const SizedBox(height: 16),
|
2023-03-02 09:57:52 +00:00
|
|
|
Padding(
|
2023-12-24 12:46:29 +00:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
2023-03-02 09:57:52 +00: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],
|
|
|
|
decoration: InputDecoration(
|
|
|
|
prefixIcon: const Icon(Icons.account_box_outlined),
|
|
|
|
errorText: controller.usernameError,
|
|
|
|
errorStyle: const TextStyle(color: Colors.orange),
|
2024-08-17 10:16:55 +00:00
|
|
|
hintText: '@username:localpart',
|
|
|
|
labelText: L10n.of(context)!.emailOrUsername,
|
2023-03-02 09:57:52 +00:00
|
|
|
),
|
2021-05-30 10:25:29 +00:00
|
|
|
),
|
2021-05-22 07:08:23 +00:00
|
|
|
),
|
2023-12-24 12:46:29 +00:00
|
|
|
const SizedBox(height: 16),
|
2023-03-02 09:57:52 +00:00
|
|
|
Padding(
|
2023-12-24 12:46:29 +00:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
2023-03-02 09:57:52 +00:00
|
|
|
child: TextField(
|
|
|
|
readOnly: controller.loading,
|
|
|
|
autocorrect: false,
|
|
|
|
autofillHints:
|
|
|
|
controller.loading ? null : [AutofillHints.password],
|
|
|
|
controller: controller.passwordController,
|
|
|
|
textInputAction: TextInputAction.go,
|
|
|
|
obscureText: !controller.showPassword,
|
|
|
|
onSubmitted: (_) => controller.login(),
|
|
|
|
decoration: InputDecoration(
|
|
|
|
prefixIcon: const Icon(Icons.lock_outlined),
|
|
|
|
errorText: controller.passwordError,
|
|
|
|
errorStyle: const TextStyle(color: Colors.orange),
|
|
|
|
suffixIcon: IconButton(
|
|
|
|
onPressed: controller.toggleShowPassword,
|
|
|
|
icon: Icon(
|
|
|
|
controller.showPassword
|
|
|
|
? Icons.visibility_off_outlined
|
|
|
|
: Icons.visibility_outlined,
|
|
|
|
color: Colors.black,
|
|
|
|
),
|
2022-04-24 05:57:08 +00:00
|
|
|
),
|
2024-08-17 10:16:55 +00:00
|
|
|
hintText: '******',
|
|
|
|
labelText: L10n.of(context)!.password,
|
2021-08-08 17:30:51 +00:00
|
|
|
),
|
2021-05-22 07:08:23 +00:00
|
|
|
),
|
|
|
|
),
|
2023-12-24 12:46:29 +00:00
|
|
|
const SizedBox(height: 16),
|
2023-03-02 09:57:52 +00:00
|
|
|
Padding(
|
2023-12-24 12:46:29 +00:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
2024-08-17 10:16:55 +00:00
|
|
|
child: ElevatedButton(
|
2023-12-24 12:46:29 +00:00
|
|
|
style: ElevatedButton.styleFrom(
|
2024-08-04 12:09:36 +00:00
|
|
|
backgroundColor: theme.colorScheme.primary,
|
|
|
|
foregroundColor: theme.colorScheme.onPrimary,
|
2023-12-24 12:46:29 +00:00
|
|
|
),
|
|
|
|
onPressed: controller.loading ? null : controller.login,
|
2024-08-17 10:16:55 +00:00
|
|
|
child: controller.loading
|
2023-12-24 12:46:29 +00:00
|
|
|
? const LinearProgressIndicator()
|
|
|
|
: Text(L10n.of(context)!.login),
|
2023-03-02 09:57:52 +00:00
|
|
|
),
|
2022-10-16 10:37:38 +00:00
|
|
|
),
|
2023-12-24 12:46:29 +00:00
|
|
|
const SizedBox(height: 16),
|
2023-03-02 09:57:52 +00:00
|
|
|
Padding(
|
2023-12-24 12:46:29 +00:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
2024-08-17 10:16:55 +00:00
|
|
|
child: TextButton(
|
2023-03-02 09:57:52 +00:00
|
|
|
onPressed: controller.loading
|
|
|
|
? () {}
|
|
|
|
: controller.passwordForgotten,
|
2023-12-24 12:46:29 +00:00
|
|
|
style: TextButton.styleFrom(
|
2024-08-04 12:09:36 +00:00
|
|
|
foregroundColor: theme.colorScheme.error,
|
2023-03-02 09:57:52 +00:00
|
|
|
),
|
2024-08-17 10:16:55 +00:00
|
|
|
child: Text(L10n.of(context)!.passwordForgotten),
|
2022-10-16 10:37:38 +00:00
|
|
|
),
|
2022-04-15 09:42:59 +00:00
|
|
|
),
|
2023-12-24 12:46:29 +00:00
|
|
|
const SizedBox(height: 16),
|
2023-03-02 09:57:52 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2021-05-22 07:08:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|