fluffychat/lib/pages/login/login_view.dart

144 lines
5.5 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2021-10-26 16:50:34 +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';
class LoginView extends StatelessWidget {
final LoginController controller;
2022-01-29 11:35:03 +00:00
const LoginView(this.controller, {Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
2022-04-15 09:42:59 +00:00
return LoginScaffold(
appBar: AppBar(
2022-10-16 10:37:38 +00:00
leading: controller.loading ? null : const BackButton(),
2022-04-15 09:42:59 +00:00
automaticallyImplyLeading: !controller.loading,
centerTitle: true,
title: Text(
L10n.of(context)!.logInTo(Matrix.of(context)
.getLoginClient()
.homeserver
.toString()
.replaceFirst('https://', '')),
),
2022-04-15 09:42:59 +00:00
),
body: Builder(builder: (context) {
return AutofillGroup(
child: ListView(
children: <Widget>[
Padding(
2022-08-05 19:04:37 +00:00
padding: const EdgeInsets.all(12.0),
2022-04-15 09:42:59 +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],
2022-07-07 16:50:13 +00:00
decoration: InputDecoration(
prefixIcon: const Icon(Icons.account_box_outlined),
2022-04-15 09:42:59 +00:00
errorText: controller.usernameError,
2022-08-06 11:35:59 +00:00
errorStyle: const TextStyle(color: Colors.orange),
2022-04-15 09:42:59 +00:00
hintText: L10n.of(context)!.emailOrUsername,
2021-05-30 10:25:29 +00:00
),
),
2022-04-15 09:42:59 +00:00
),
Padding(
2022-08-05 19:04:37 +00:00
padding: const EdgeInsets.all(12.0),
2022-04-15 09:42:59 +00:00
child: TextField(
readOnly: controller.loading,
autocorrect: false,
autofillHints:
controller.loading ? null : [AutofillHints.password],
controller: controller.passwordController,
textInputAction: TextInputAction.go,
2022-10-27 13:32:05 +00:00
obscureText: !controller.showPassword,
onSubmitted: (_) => controller.login(),
2022-07-07 16:50:13 +00:00
decoration: InputDecoration(
prefixIcon: const Icon(Icons.lock_outlined),
2022-04-15 09:42:59 +00:00
errorText: controller.passwordError,
2022-08-06 11:35:59 +00:00
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-15 09:42:59 +00:00
hintText: L10n.of(context)!.password,
),
),
2022-04-15 09:42:59 +00:00
),
Hero(
tag: 'signinButton',
child: Padding(
2022-08-05 19:04:37 +00:00
padding: const EdgeInsets.all(12.0),
2022-12-29 19:38:13 +00:00
child: ElevatedButton.icon(
2022-10-16 10:37:38 +00:00
style: ElevatedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
foregroundColor: Theme.of(context).colorScheme.onPrimary,
),
onPressed: controller.loading ? null : controller.login,
2022-12-29 19:38:13 +00:00
icon: const Icon(Icons.login_outlined),
label: controller.loading
2022-04-15 09:42:59 +00:00
? const LinearProgressIndicator()
: Text(L10n.of(context)!.login),
),
),
2022-04-15 09:42:59 +00:00
),
2022-10-16 10:37:38 +00:00
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
children: [
Expanded(
2022-08-06 11:35:59 +00:00
child: Divider(
2022-10-16 10:37:38 +00:00
thickness: 1,
2022-11-04 12:31:29 +00:00
color: Theme.of(context).dividerColor,
2022-08-06 11:35:59 +00:00
),
2022-04-15 09:42:59 +00:00
),
2022-10-16 10:37:38 +00:00
Padding(
padding: const EdgeInsets.all(12.0),
child: Text(
L10n.of(context)!.or,
style: const TextStyle(fontSize: 18),
),
),
Expanded(
2022-08-06 11:35:59 +00:00
child: Divider(
2022-10-16 10:37:38 +00:00
thickness: 1,
2022-11-04 12:31:29 +00:00
color: Theme.of(context).dividerColor,
2022-10-16 10:37:38 +00:00
),
),
],
),
2022-04-15 09:42:59 +00:00
),
Padding(
2022-08-05 19:04:37 +00:00
padding: const EdgeInsets.all(12.0),
2022-12-29 19:38:13 +00:00
child: ElevatedButton.icon(
2022-04-15 09:42:59 +00:00
onPressed:
controller.loading ? () {} : controller.passwordForgotten,
2022-10-16 10:37:38 +00:00
style: ElevatedButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.error,
backgroundColor: Theme.of(context).colorScheme.onError,
),
2022-12-29 19:38:13 +00:00
icon: const Icon(Icons.safety_check_outlined),
label: Text(L10n.of(context)!.passwordForgotten),
2022-04-15 09:42:59 +00:00
),
),
],
),
);
}),
);
}
}