fluffychat/lib/pages/login/login_view.dart

144 lines
5.4 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2021-10-26 18:50:34 +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';
class LoginView extends StatelessWidget {
final LoginController controller;
2022-01-29 12:35:03 +01:00
const LoginView(this.controller, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
2022-04-15 11:42:59 +02:00
return LoginScaffold(
appBar: AppBar(
2022-10-16 12:37:38 +02:00
leading: controller.loading ? null : const BackButton(),
2022-04-15 11:42:59 +02:00
automaticallyImplyLeading: !controller.loading,
centerTitle: true,
title: Text(
L10n.of(context)!.logInTo(Matrix.of(context)
.getLoginClient()
.homeserver
.toString()
.replaceFirst('https://', '')),
),
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,
2022-08-06 13:35:59 +02:00
errorStyle: const TextStyle(color: Colors.orange),
2022-04-15 11:42:59 +02:00
hintText: L10n.of(context)!.emailOrUsername,
2021-05-30 12:25:29 +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,
2022-10-27 15:32:05 +02:00
obscureText: !controller.showPassword,
2022-04-15 11:42:59 +02:00
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,
2022-08-06 13:35:59 +02:00
errorStyle: const TextStyle(color: Colors.orange),
2022-10-27 15:32:05 +02:00
suffixIcon: InkWell(
onTap: controller.toggleShowPassword,
child: Icon(
controller.showPassword
? Icons.visibility_off_outlined
: Icons.visibility_outlined,
color: Colors.black,
),
),
2022-04-15 11:42:59 +02:00
hintText: L10n.of(context)!.password,
),
),
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(
2022-10-16 12:37:38 +02:00
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
),
2022-02-19 13:11:59 +01:00
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),
),
),
2022-04-15 11:42:59 +02:00
),
2022-10-16 12:37:38 +02:00
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
children: [
Expanded(
2022-08-06 13:35:59 +02:00
child: Divider(
2022-10-16 12:37:38 +02:00
thickness: 1,
2022-11-04 13:31:29 +01:00
color: Theme.of(context).dividerColor,
2022-08-06 13:35:59 +02:00
),
2022-04-15 11:42:59 +02:00
),
2022-10-16 12:37:38 +02:00
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(
L10n.of(context)!.or,
style: const TextStyle(fontSize: 18),
),
),
Expanded(
2022-08-06 13:35:59 +02:00
child: Divider(
2022-10-16 12:37:38 +02:00
thickness: 1,
2022-11-04 13:31:29 +01:00
color: Theme.of(context).dividerColor,
2022-10-16 12:37:38 +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: ElevatedButton(
onPressed:
controller.loading ? () {} : controller.passwordForgotten,
2022-10-16 12:37:38 +02:00
style: ElevatedButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.error,
backgroundColor: Theme.of(context).colorScheme.onError,
),
2022-04-15 11:42:59 +02:00
child: Text(L10n.of(context)!.passwordForgotten),
),
),
],
),
);
}),
);
}
}