From 4f9001cb2bbf3966031d1c64af7e7ae251c5695f Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 19 Feb 2021 17:38:12 +0100 Subject: [PATCH] Remove useless configuration load checks --- lib/ui/routes/create_account_route.dart | 10 +------- .../settings/account_privacy_settings.dart | 1 - lib/ui/widgets/new_password_input_widget.dart | 24 ++----------------- 3 files changed, 3 insertions(+), 32 deletions(-) diff --git a/lib/ui/routes/create_account_route.dart b/lib/ui/routes/create_account_route.dart index eba23ea..e5dfd7f 100644 --- a/lib/ui/routes/create_account_route.dart +++ b/lib/ui/routes/create_account_route.dart @@ -1,8 +1,6 @@ import 'package:comunic/helpers/account_helper.dart'; -import 'package:comunic/helpers/server_config_helper.dart'; import 'package:comunic/models/config.dart'; import 'package:comunic/models/new_account.dart'; -import 'package:comunic/ui/widgets/async_screen_widget.dart'; import 'package:comunic/ui/widgets/new_password_input_widget.dart'; import 'package:comunic/utils/input_utils.dart'; import 'package:comunic/utils/intl_utils.dart'; @@ -76,13 +74,7 @@ class __CreateAccountRouteBodyState extends State<_CreateAccountRouteBody> { "An error occurred while creating your account. Please try again."); @override - Widget build(BuildContext context) => AsyncScreenWidget( - onReload: () => ServerConfigurationHelper.ensureLoaded(), - onBuild: () => _buildForm(), - errorMessage: tr("Failed to load server configuration !"), - ); - - Widget _buildForm() { + Widget build(BuildContext context) { if (_isCreating) return Center( child: CircularProgressIndicator(), diff --git a/lib/ui/routes/settings/account_privacy_settings.dart b/lib/ui/routes/settings/account_privacy_settings.dart index a29a715..458c13e 100644 --- a/lib/ui/routes/settings/account_privacy_settings.dart +++ b/lib/ui/routes/settings/account_privacy_settings.dart @@ -30,7 +30,6 @@ class _AccountPrivacySettingsState extends State { String _cachedPassword; Future _loadSettings() async { - await ServerConfigurationHelper.ensureLoaded(); _serverConfig = ServerConfigurationHelper.config; _userSettings = await SettingsHelper.getDataConservationPolicy(); } diff --git a/lib/ui/widgets/new_password_input_widget.dart b/lib/ui/widgets/new_password_input_widget.dart index 6d47273..3ed8bcc 100644 --- a/lib/ui/widgets/new_password_input_widget.dart +++ b/lib/ui/widgets/new_password_input_widget.dart @@ -1,7 +1,6 @@ import 'package:comunic/helpers/server_config_helper.dart'; import 'package:comunic/models/server_config.dart'; import 'package:comunic/utils/intl_utils.dart'; -import 'package:comunic/utils/ui_utils.dart'; import 'package:flutter/material.dart'; /// New password input widget @@ -47,32 +46,13 @@ class NewPasswordInputWidget extends StatefulWidget { class NewPasswordInputWidgetState extends State { final TextEditingController _controller = TextEditingController(); - bool _ready = false; String get value => _controller.text; - bool get valid => _ready && value.isNotEmpty && (_errorMessage ?? "").isEmpty; + bool get valid => value.isNotEmpty && (_errorMessage ?? "").isEmpty; PasswordPolicy get _policy => ServerConfigurationHelper.config.passwordPolicy; - @override - void initState() { - super.initState(); - - _init(); - } - - /// Make sure server configuration is loaded - void _init() async { - try { - await ServerConfigurationHelper.ensureLoaded(); - setState(() => _ready = true); - } catch (e, s) { - print("Failed to initialize NewPasswordInputWidget! : $e - $s"); - showSimpleSnack(context, tr("Failed to retrieve server configuration!")); - } - } - @override void didUpdateWidget(covariant NewPasswordInputWidget oldWidget) { super.didUpdateWidget(oldWidget); @@ -102,7 +82,7 @@ class NewPasswordInputWidgetState extends State { /// Generate an error message associated with current password String get _errorMessage { - if (!_ready || value.isEmpty) return null; + if (value.isEmpty) return null; // Mandatory checks if (!_policy.allowMailInPassword &&