refactor: rename UI to View and MVC login page

This commit is contained in:
Christian Pauly 2021-05-22 09:08:23 +02:00
parent 3e7269d970
commit cc113bb61a
48 changed files with 146 additions and 125 deletions

View File

@ -13,10 +13,10 @@ import 'package:fluffychat/pages/chat_details.dart';
import 'package:fluffychat/pages/chat_encryption_settings.dart';
import 'package:fluffychat/pages/chat_list.dart';
import 'package:fluffychat/pages/chat_permissions_settings.dart';
import 'package:fluffychat/pages/views/empty_page_ui.dart';
import 'package:fluffychat/pages/views/empty_page_view.dart';
import 'package:fluffychat/widgets/layouts/loading_view.dart';
import 'package:fluffychat/widgets/log_view.dart';
import 'package:fluffychat/pages/views/login_ui.dart';
import 'package:fluffychat/pages/login.dart';
import 'package:fluffychat/pages/new_group.dart';
import 'package:fluffychat/pages/new_private_chat.dart';
import 'package:fluffychat/pages/search.dart';

View File

@ -6,7 +6,7 @@ import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:file_picker_cross/file_picker_cross.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pages/views/chat_ui.dart';
import 'package:fluffychat/pages/views/chat_view.dart';
import 'package:fluffychat/pages/recording_dialog.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

View File

@ -4,7 +4,7 @@ import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:file_picker_cross/file_picker_cross.dart';
import 'package:fluffychat/pages/views/chat_details_ui.dart';
import 'package:fluffychat/pages/views/chat_details_view.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/services.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';

View File

@ -1,6 +1,6 @@
import 'package:famedlysdk/encryption.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/pages/views/chat_encryption_settings_ui.dart';
import 'package:fluffychat/pages/views/chat_encryption_settings_view.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'key_verification_dialog.dart';

View File

@ -5,7 +5,7 @@ import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/fluffy_share.dart';
import 'package:fluffychat/pages/views/chat_list_ui.dart';
import 'package:fluffychat/pages/views/chat_list_view.dart';
import 'package:flutter/cupertino.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/platform_infos.dart';

View File

@ -2,7 +2,7 @@ import 'dart:developer';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:fluffychat/pages/views/chat_permissions_settings_ui.dart';
import 'package:fluffychat/pages/views/chat_permissions_settings_view.dart';
import 'package:fluffychat/pages/permission_slider_dialog.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/widgets/matrix.dart';

View File

@ -1,7 +1,7 @@
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:famedlysdk/encryption/utils/key_verification.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/pages/views/device_settings_ui.dart';
import 'package:fluffychat/pages/views/device_settings_view.dart';
import 'package:fluffychat/pages/key_verification_dialog.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:flutter/material.dart';

View File

@ -2,7 +2,7 @@ import 'dart:async';
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/pages/views/homeserver_picker_ui.dart';
import 'package:fluffychat/pages/views/homeserver_picker_view.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/config/setting_keys.dart';

View File

@ -1,7 +1,7 @@
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:fluffychat/pages/views/image_viewer_ui.dart';
import 'package:fluffychat/pages/views/image_viewer_view.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';

View File

@ -3,7 +3,7 @@ import 'dart:async';
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/pages/views/invitation_selection_ui.dart';
import 'package:fluffychat/pages/views/invitation_selection_view.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';

View File

@ -3,21 +3,22 @@ import 'dart:async';
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/widgets/layouts/one_page_card.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import '../../utils/platform_infos.dart';
import '../utils/platform_infos.dart';
import 'package:email_validator/email_validator.dart';
import 'views/login_view.dart';
class Login extends StatefulWidget {
@override
_LoginState createState() => _LoginState();
LoginController createState() => LoginController();
}
class _LoginState extends State<Login> {
class LoginController extends State<Login> {
final TextEditingController usernameController = TextEditingController();
final TextEditingController passwordController = TextEditingController();
String usernameError;
@ -25,7 +26,9 @@ class _LoginState extends State<Login> {
bool loading = false;
bool showPassword = false;
void login(BuildContext context) async {
void toggleShowPassword() => setState(() => showPassword = !showPassword);
void login([_]) async {
final matrix = Matrix.of(context);
if (usernameController.text.isEmpty) {
setState(() => usernameError = L10n.of(context).pleaseEnterYourUsername);
@ -81,15 +84,15 @@ class _LoginState extends State<Login> {
Timer _coolDown;
void _checkWellKnownWithCoolDown(String userId, BuildContext context) async {
void checkWellKnownWithCoolDown(String userId) async {
_coolDown?.cancel();
_coolDown = Timer(
Duration(seconds: 1),
() => _checkWellKnown(userId, context),
() => _checkWellKnown(userId),
);
}
void _checkWellKnown(String userId, BuildContext context) async {
void _checkWellKnown(String userId) async {
setState(() => usernameError = null);
if (!userId.isValidMatrixId) return;
try {
@ -110,7 +113,7 @@ class _LoginState extends State<Login> {
}
}
void _passwordForgotten(BuildContext context) async {
void passwordForgotten() async {
final input = await showTextInputDialog(
context: context,
title: L10n.of(context).enterAnEmailAddress,
@ -183,98 +186,7 @@ class _LoginState extends State<Login> {
static int sendAttempt = 0;
@override
Widget build(BuildContext context) {
return OnePageCard(
child: Scaffold(
appBar: AppBar(
leading: loading ? Container() : BackButton(),
elevation: 0,
title: Text(
L10n.of(context).logInTo(Matrix.of(context)
.client
.homeserver
.toString()
.replaceFirst('https://', '')),
),
),
body: Builder(builder: (context) {
return ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(12.0),
child: TextField(
readOnly: loading,
autocorrect: false,
autofocus: true,
onChanged: (t) => _checkWellKnownWithCoolDown(t, context),
controller: usernameController,
autofillHints: loading ? null : [AutofillHints.username],
decoration: InputDecoration(
prefixIcon: Icon(Icons.account_box_outlined),
hintText:
'@${L10n.of(context).username.toLowerCase()}:domain',
errorText: usernameError,
labelText: L10n.of(context).username),
),
),
Padding(
padding: const EdgeInsets.all(12.0),
child: TextField(
readOnly: loading,
autocorrect: false,
autofillHints: loading ? null : [AutofillHints.password],
controller: passwordController,
obscureText: !showPassword,
onSubmitted: (t) => login(context),
decoration: InputDecoration(
prefixIcon: Icon(Icons.lock_outlined),
hintText: '****',
errorText: passwordError,
suffixIcon: IconButton(
tooltip: L10n.of(context).showPassword,
icon: Icon(showPassword
? Icons.visibility_off_outlined
: Icons.visibility_outlined),
onPressed: () =>
setState(() => showPassword = !showPassword),
),
labelText: L10n.of(context).password),
),
),
SizedBox(height: 12),
Hero(
tag: 'loginButton',
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 12),
child: ElevatedButton(
onPressed: loading ? null : () => login(context),
child: loading
? LinearProgressIndicator()
: Text(
L10n.of(context).login.toUpperCase(),
style: TextStyle(color: Colors.white, fontSize: 16),
),
),
),
),
Center(
child: TextButton(
onPressed: () => _passwordForgotten(context),
child: Text(
L10n.of(context).passwordForgotten,
style: TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
),
),
),
),
],
);
}),
),
);
}
Widget build(BuildContext context) => LoginView(this);
}
extension on String {

View File

@ -1,6 +1,6 @@
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:famedlysdk/famedlysdk.dart' as sdk;
import 'package:fluffychat/pages/views/new_group_ui.dart';
import 'package:fluffychat/pages/views/new_group_view.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';

View File

@ -3,7 +3,7 @@ import 'dart:async';
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/fluffy_share.dart';
import 'package:fluffychat/pages/views/new_private_chat_ui.dart';
import 'package:fluffychat/pages/views/new_private_chat_view.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';

View File

@ -7,7 +7,7 @@ import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'views/search_ui.dart';
import 'views/search_view.dart';
class Search extends StatefulWidget {
final String alias;

View File

@ -14,7 +14,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:image_picker/image_picker.dart';
import 'views/settings_ui.dart';
import 'views/settings_view.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'bootstrap_dialog.dart';
import '../widgets/matrix.dart';

View File

@ -5,7 +5,7 @@ import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'views/settings_3pid_ui.dart';
import 'views/settings_3pid_view.dart';
class Settings3Pid extends StatefulWidget {
static int sendAttempt = 0;

View File

@ -9,7 +9,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:image_picker/image_picker.dart';
import 'views/settings_emotes_ui.dart';
import 'views/settings_emotes_view.dart';
import '../widgets/matrix.dart';
class EmotesSettings extends StatefulWidget {

View File

@ -1,7 +1,7 @@
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:flutter/material.dart';
import 'views/settings_ignore_list_ui.dart';
import 'views/settings_ignore_list_view.dart';
import '../widgets/matrix.dart';
class SettingsIgnoreList extends StatefulWidget {

View File

@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'views/settings_multiple_emotes_ui.dart';
import 'views/settings_multiple_emotes_view.dart';
class MultipleEmotesSettings extends StatefulWidget {
final String roomId;

View File

@ -6,7 +6,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:open_noti_settings/open_noti_settings.dart';
import 'views/settings_notifications_ui.dart';
import 'views/settings_notifications_view.dart';
import '../widgets/matrix.dart';
class NotificationSettingsItem {

View File

@ -6,7 +6,7 @@ import 'package:fluffychat/config/setting_keys.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'views/settings_style_ui.dart';
import 'views/settings_style_view.dart';
import '../widgets/matrix.dart';
class SettingsStyle extends StatefulWidget {

View File

@ -1,7 +1,7 @@
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:file_picker_cross/file_picker_cross.dart';
import 'package:fluffychat/pages/views/sign_up_ui.dart';
import 'package:fluffychat/pages/views/sign_up_view.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/cupertino.dart';

View File

@ -4,7 +4,7 @@ import 'package:email_validator/email_validator.dart';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/get_client_secret.dart';
import 'package:fluffychat/pages/views/sign_up_password_ui.dart';
import 'package:fluffychat/pages/views/sign_up_password_view.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';

View File

@ -7,7 +7,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'views/user_bottom_sheet_ui.dart';
import 'views/user_bottom_sheet_view.dart';
class UserBottomSheet extends StatefulWidget {
final User user;

View File

@ -0,0 +1,109 @@
import 'package:fluffychat/widgets/layouts/one_page_card.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
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(
leading: controller.loading ? Container() : BackButton(),
elevation: 0,
title: Text(
L10n.of(context).logInTo(Matrix.of(context)
.client
.homeserver
.toString()
.replaceFirst('https://', '')),
),
),
body: Builder(builder: (context) {
return 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(
prefixIcon: Icon(Icons.account_box_outlined),
hintText:
'@${L10n.of(context).username.toLowerCase()}:domain',
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(
prefixIcon: 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),
),
),
SizedBox(height: 12),
Hero(
tag: 'loginButton',
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 12),
child: ElevatedButton(
onPressed: controller.loading
? null
: () => controller.login(context),
child: controller.loading
? LinearProgressIndicator()
: Text(
L10n.of(context).login.toUpperCase(),
style: TextStyle(color: Colors.white, fontSize: 16),
),
),
),
),
Center(
child: TextButton(
onPressed: controller.passwordForgotten,
child: Text(
L10n.of(context).passwordForgotten,
style: TextStyle(
color: Colors.blue,
decoration: TextDecoration.underline,
),
),
),
),
],
);
}),
),
);
}
}