fluffychat/lib/pages/login/login_view.dart

146 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-09-06 20:21:11 +02:00
leading:
controller.loading ? null : const BackButton(color: Colors.white),
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://', '')),
style: const TextStyle(color: Colors.white),
),
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,
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
),
),
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,
2022-08-06 13:35:59 +02:00
errorStyle: const TextStyle(color: Colors.orange),
2022-04-15 11:42:59 +02:00
suffixIcon: IconButton(
tooltip: L10n.of(context)!.showPassword,
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,
),
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),
),
),
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),
),
),
2022-04-15 11:42:59 +02:00
),
Row(
children: [
2022-08-06 13:35:59 +02:00
const Expanded(
child: Divider(
color: Colors.white,
thickness: 1,
)),
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: Text(
L10n.of(context)!.or,
2022-08-06 13:35:59 +02:00
style: const TextStyle(
color: Colors.white,
fontSize: 18,
),
2022-04-15 11:42:59 +02:00
),
),
2022-08-06 13:35:59 +02:00
const Expanded(
child: Divider(
color: Colors.white,
thickness: 1,
)),
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-08-31 19:54:22 +02:00
style: ElevatedButton.styleFrom(foregroundColor: Colors.red),
2022-04-15 11:42:59 +02:00
child: Text(L10n.of(context)!.passwordForgotten),
),
),
],
),
);
}),
);
}
}