From 38c1474d2e8b3a9431eae1603c951489b8b27c75 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 27 Apr 2020 18:58:18 +0200 Subject: [PATCH] Can update "allow posts from friends" setting --- lib/models/general_settings.dart | 2 +- .../general_account_settings.dart | 22 ++++++++++++++----- lib/ui/widgets/async_screen_widget.dart | 7 +++++- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/models/general_settings.dart b/lib/models/general_settings.dart index 9008e03..f271a67 100644 --- a/lib/models/general_settings.dart +++ b/lib/models/general_settings.dart @@ -11,7 +11,7 @@ class GeneralSettings { String lastName; UserPageVisibility pageVisibility; bool allowComments; - final bool allowPostsFromFriends; + bool allowPostsFromFriends; bool allowComunicEmails; final bool publicFriendsList; final String virtualDirectory; diff --git a/lib/ui/routes/account_settings/general_account_settings.dart b/lib/ui/routes/account_settings/general_account_settings.dart index 5a41f6c..04fac99 100644 --- a/lib/ui/routes/account_settings/general_account_settings.dart +++ b/lib/ui/routes/account_settings/general_account_settings.dart @@ -50,11 +50,13 @@ class __GeneralAccountSettingsBodyState @override Widget build(BuildContext context) { return AsyncScreenWidget( - key: _key, - onReload: () async => - _settings = await SettingsHelper.getGeneralSettings(), - onBuild: _buildSettings, - errorMessage: tr("Could not load general settings!")); + key: _key, + onReload: () async => + _settings = await SettingsHelper.getGeneralSettings(), + onBuild: _buildSettings, + errorMessage: tr("Could not load general settings!"), + showOldDataWhileUpdating: true, + ); } Widget _buildSettings() { @@ -166,6 +168,16 @@ class __GeneralAccountSettingsBodyState }, switchValue: _settings.allowComments, ), + + // Allow posts from friends + SettingsTile.switchTile( + title: tr("Allow posts from your friends on your page"), + onToggle: (v) { + _settings.allowPostsFromFriends = v; + _updateSettings(); + }, + switchValue: _settings.allowPostsFromFriends, + ), ]; } diff --git a/lib/ui/widgets/async_screen_widget.dart b/lib/ui/widgets/async_screen_widget.dart index 034b8a3..e8d800c 100644 --- a/lib/ui/widgets/async_screen_widget.dart +++ b/lib/ui/widgets/async_screen_widget.dart @@ -25,14 +25,19 @@ class AsyncScreenWidget extends StatefulWidget { /// Error message that will be shown in case of error final String errorMessage; + /// Specify whether old data can be kept or not while updating this widget + final bool showOldDataWhileUpdating; + const AsyncScreenWidget({ Key key, @required this.onReload, @required this.onBuild, @required this.errorMessage, + this.showOldDataWhileUpdating = false, }) : assert(onReload != null), assert(onBuild != null), assert(errorMessage != null), + assert(showOldDataWhileUpdating != null), super(key: key); @override @@ -75,7 +80,7 @@ class AsyncScreenWidgetState extends SafeState { try { setState(() { error = false; - ready = false; + ready = widget.showOldDataWhileUpdating; }); // Call parent method