fluffychat/lib/pages/login/login_view.dart

110 lines
4.1 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
import 'package:fluffychat/widgets/layouts/one_page_card.dart';
import 'package:fluffychat/widgets/matrix.dart';
2021-11-09 21:32:16 +01:00
import 'login.dart';
class LoginView extends StatelessWidget {
final LoginController controller;
const LoginView(this.controller, {Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return OnePageCard(
child: Scaffold(
appBar: AppBar(
2021-10-14 18:09:30 +02:00
leading: controller.loading ? Container() : const BackButton(),
elevation: 0,
title: Text(
L10n.of(context).logInTo(Matrix.of(context)
.getLoginClient()
.homeserver
.toString()
.replaceFirst('https://', '')),
),
),
body: Builder(builder: (context) {
return AutofillGroup(
child: ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(12.0),
child: TextField(
readOnly: controller.loading,
autocorrect: false,
autofocus: true,
onChanged: controller.checkWellKnownWithCoolDown,
controller: controller.usernameController,
autofillHints:
controller.loading ? null : [AutofillHints.username],
decoration: InputDecoration(
2021-10-14 18:09:30 +02:00
prefixIcon: const Icon(Icons.account_box_outlined),
hintText: L10n.of(context).username,
errorText: controller.usernameError,
labelText: L10n.of(context).username),
),
),
Padding(
padding: const EdgeInsets.all(12.0),
child: TextField(
readOnly: controller.loading,
autocorrect: false,
autofillHints:
controller.loading ? null : [AutofillHints.password],
controller: controller.passwordController,
obscureText: !controller.showPassword,
onSubmitted: controller.login,
decoration: InputDecoration(
2021-10-14 18:09:30 +02:00
prefixIcon: const Icon(Icons.lock_outlined),
hintText: '****',
errorText: controller.passwordError,
suffixIcon: IconButton(
tooltip: L10n.of(context).showPassword,
icon: Icon(controller.showPassword
? Icons.visibility_off_outlined
: Icons.visibility_outlined),
onPressed: controller.toggleShowPassword,
),
labelText: L10n.of(context).password,
2021-05-30 12:25:29 +02:00
),
),
),
2021-10-14 18:09:30 +02:00
const SizedBox(height: 12),
Hero(
tag: 'loginButton',
child: Padding(
2021-10-14 18:09:30 +02:00
padding: const EdgeInsets.symmetric(horizontal: 12),
child: ElevatedButton(
onPressed: controller.loading
? null
: () => controller.login(context),
child: controller.loading
2021-10-14 18:09:30 +02:00
? const LinearProgressIndicator()
: Text(L10n.of(context).login),
),
),
),
Center(
child: TextButton(
onPressed: controller.passwordForgotten,
child: Text(
L10n.of(context).passwordForgotten,
2021-10-14 18:09:30 +02:00
style: const TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
),
),
),
),
],
),
);
}),
),
);
}
}