chore: load client within login page instead of passing to route (#3434)
parent
7e07289ae7
commit
0b577270a5
@ -1,145 +1,145 @@
|
||||
import 'package:flutter/material.dart';
|
||||
// import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:fluffychat/l10n/l10n.dart';
|
||||
import 'package:fluffychat/widgets/layouts/login_scaffold.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'login.dart';
|
||||
// import 'package:fluffychat/l10n/l10n.dart';
|
||||
// import 'package:fluffychat/widgets/layouts/login_scaffold.dart';
|
||||
// import 'package:fluffychat/widgets/matrix.dart';
|
||||
// import 'login.dart';
|
||||
|
||||
class LoginView extends StatelessWidget {
|
||||
final LoginController controller;
|
||||
// class LoginView extends StatelessWidget {
|
||||
// final LoginController controller;
|
||||
|
||||
const LoginView(this.controller, {super.key});
|
||||
// const LoginView(this.controller, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// final theme = Theme.of(context);
|
||||
|
||||
final homeserver = controller.widget.client.homeserver
|
||||
.toString()
|
||||
.replaceFirst('https://', '');
|
||||
final title = L10n.of(context).logInTo(homeserver);
|
||||
final titleParts = title.split(homeserver);
|
||||
// final homeserver = controller.widget.client.homeserver
|
||||
// .toString()
|
||||
// .replaceFirst('https://', '');
|
||||
// final title = L10n.of(context).logInTo(homeserver);
|
||||
// final titleParts = title.split(homeserver);
|
||||
|
||||
return LoginScaffold(
|
||||
enforceMobileMode:
|
||||
Matrix.of(context).widget.clients.any((client) => client.isLogged()),
|
||||
appBar: AppBar(
|
||||
leading:
|
||||
controller.loadingSignIn ? null : const Center(child: BackButton()),
|
||||
automaticallyImplyLeading: !controller.loadingSignIn,
|
||||
titleSpacing: !controller.loadingSignIn ? 0 : null,
|
||||
title: Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
TextSpan(text: titleParts.first),
|
||||
TextSpan(
|
||||
text: homeserver,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
TextSpan(text: titleParts.last),
|
||||
],
|
||||
),
|
||||
style: const TextStyle(fontSize: 18),
|
||||
),
|
||||
),
|
||||
body: Builder(
|
||||
builder: (context) {
|
||||
return AutofillGroup(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
children: <Widget>[
|
||||
Hero(
|
||||
tag: 'info-logo',
|
||||
child: Image.asset('assets/banner_transparent.png'),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
child: TextField(
|
||||
readOnly: controller.loadingSignIn,
|
||||
autocorrect: false,
|
||||
autofocus: true,
|
||||
onChanged: controller.checkWellKnownWithCoolDown,
|
||||
controller: controller.usernameController,
|
||||
textInputAction: TextInputAction.next,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
autofillHints: controller.loadingSignIn
|
||||
? null
|
||||
: [AutofillHints.username],
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.account_box_outlined),
|
||||
errorText: controller.usernameError,
|
||||
errorStyle: const TextStyle(color: Colors.orange),
|
||||
hintText: '@username:domain',
|
||||
labelText: L10n.of(context).emailOrUsername,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
child: TextField(
|
||||
readOnly: controller.loadingSignIn,
|
||||
autocorrect: false,
|
||||
autofillHints: controller.loadingSignIn
|
||||
? 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,
|
||||
),
|
||||
),
|
||||
hintText: '******',
|
||||
labelText: L10n.of(context).password,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: theme.colorScheme.primary,
|
||||
foregroundColor: theme.colorScheme.onPrimary,
|
||||
),
|
||||
onPressed:
|
||||
controller.loadingSignIn ? null : controller.login,
|
||||
child: controller.loadingSignIn
|
||||
? const LinearProgressIndicator()
|
||||
: Text(L10n.of(context).login),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
child: TextButton(
|
||||
onPressed: controller.loadingSignIn
|
||||
? () {}
|
||||
: controller.passwordForgotten,
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: theme.colorScheme.error,
|
||||
),
|
||||
child: Text(L10n.of(context).passwordForgotten),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
// return LoginScaffold(
|
||||
// enforceMobileMode:
|
||||
// Matrix.of(context).widget.clients.any((client) => client.isLogged()),
|
||||
// appBar: AppBar(
|
||||
// leading:
|
||||
// controller.loadingSignIn ? null : const Center(child: BackButton()),
|
||||
// automaticallyImplyLeading: !controller.loadingSignIn,
|
||||
// titleSpacing: !controller.loadingSignIn ? 0 : null,
|
||||
// title: Text.rich(
|
||||
// TextSpan(
|
||||
// children: [
|
||||
// TextSpan(text: titleParts.first),
|
||||
// TextSpan(
|
||||
// text: homeserver,
|
||||
// style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
// ),
|
||||
// TextSpan(text: titleParts.last),
|
||||
// ],
|
||||
// ),
|
||||
// style: const TextStyle(fontSize: 18),
|
||||
// ),
|
||||
// ),
|
||||
// body: Builder(
|
||||
// builder: (context) {
|
||||
// return AutofillGroup(
|
||||
// child: ListView(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
// children: <Widget>[
|
||||
// Hero(
|
||||
// tag: 'info-logo',
|
||||
// child: Image.asset('assets/banner_transparent.png'),
|
||||
// ),
|
||||
// const SizedBox(height: 16),
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
// child: TextField(
|
||||
// readOnly: controller.loadingSignIn,
|
||||
// autocorrect: false,
|
||||
// autofocus: true,
|
||||
// onChanged: controller.checkWellKnownWithCoolDown,
|
||||
// controller: controller.usernameController,
|
||||
// textInputAction: TextInputAction.next,
|
||||
// keyboardType: TextInputType.emailAddress,
|
||||
// autofillHints: controller.loadingSignIn
|
||||
// ? null
|
||||
// : [AutofillHints.username],
|
||||
// decoration: InputDecoration(
|
||||
// prefixIcon: const Icon(Icons.account_box_outlined),
|
||||
// errorText: controller.usernameError,
|
||||
// errorStyle: const TextStyle(color: Colors.orange),
|
||||
// hintText: '@username:domain',
|
||||
// labelText: L10n.of(context).emailOrUsername,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(height: 16),
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
// child: TextField(
|
||||
// readOnly: controller.loadingSignIn,
|
||||
// autocorrect: false,
|
||||
// autofillHints: controller.loadingSignIn
|
||||
// ? 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,
|
||||
// ),
|
||||
// ),
|
||||
// hintText: '******',
|
||||
// labelText: L10n.of(context).password,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(height: 16),
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
// child: ElevatedButton(
|
||||
// style: ElevatedButton.styleFrom(
|
||||
// backgroundColor: theme.colorScheme.primary,
|
||||
// foregroundColor: theme.colorScheme.onPrimary,
|
||||
// ),
|
||||
// onPressed:
|
||||
// controller.loadingSignIn ? null : controller.login,
|
||||
// child: controller.loadingSignIn
|
||||
// ? const LinearProgressIndicator()
|
||||
// : Text(L10n.of(context).login),
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(height: 16),
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
// child: TextButton(
|
||||
// onPressed: controller.loadingSignIn
|
||||
// ? () {}
|
||||
// : controller.passwordForgotten,
|
||||
// style: TextButton.styleFrom(
|
||||
// foregroundColor: theme.colorScheme.error,
|
||||
// ),
|
||||
// child: Text(L10n.of(context).passwordForgotten),
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(height: 16),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
Loading…
Reference in New Issue