From 67e881af0d147934dec83ca8afe63c2a251d6153 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 13 May 2020 18:26:21 +0200 Subject: [PATCH] Can toggle performances overlay --- lib/helpers/preferences_helper.dart | 9 ++++++--- lib/main.dart | 7 ++++--- lib/models/application_preferences.dart | 5 ++++- lib/ui/routes/settings/application_settings.dart | 11 +++++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/lib/helpers/preferences_helper.dart b/lib/helpers/preferences_helper.dart index e937783..69f596f 100644 --- a/lib/helpers/preferences_helper.dart +++ b/lib/helpers/preferences_helper.dart @@ -14,12 +14,14 @@ enum PreferencesKeyList { LOGIN_TOKENS, ENABLE_DARK_THEME, FORCE_MOBILE_MODE, + SHOW_PERFORMANCE_OVERLAY, } const _PreferenceKeysName = { PreferencesKeyList.LOGIN_TOKENS: "login_tokens", PreferencesKeyList.ENABLE_DARK_THEME: "dark_theme", PreferencesKeyList.FORCE_MOBILE_MODE: "force_mobile_mode", + PreferencesKeyList.SHOW_PERFORMANCE_OVERLAY: "perfs_overlay", }; class PreferencesHelper { @@ -79,9 +81,10 @@ class PreferencesHelper { /// Get all settings as an [ApplicationPreferences] object ApplicationPreferences get preferences => ApplicationPreferences( - enableDarkMode: getBool(PreferencesKeyList.ENABLE_DARK_THEME), - forceMobileMode: getBool(PreferencesKeyList.FORCE_MOBILE_MODE), - ); + enableDarkMode: getBool(PreferencesKeyList.ENABLE_DARK_THEME), + forceMobileMode: getBool(PreferencesKeyList.FORCE_MOBILE_MODE), + showPerformancesOverlay: + getBool(PreferencesKeyList.SHOW_PERFORMANCE_OVERLAY)); /// Apply new preferences Future setPreferences(ApplicationPreferences preferences) async { diff --git a/lib/main.dart b/lib/main.dart index af5f564..3868258 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -47,12 +47,13 @@ class ComunicApplicationState extends State { @override Widget build(BuildContext context) { + final prefs = widget.preferences.preferences; + return MaterialApp( debugShowCheckedModeBanner: false, home: AccountHelper.isUserIDLoaded ? InitializeWidget() : LoginRoute(), - theme: widget.preferences.preferences.enableDarkMode - ? ThemeData.dark() - : null, + theme: prefs.enableDarkMode ? ThemeData.dark() : null, + showPerformanceOverlay: prefs.showPerformancesOverlay, ); } } diff --git a/lib/models/application_preferences.dart b/lib/models/application_preferences.dart index d458705..6bbc83b 100644 --- a/lib/models/application_preferences.dart +++ b/lib/models/application_preferences.dart @@ -7,10 +7,13 @@ import 'package:flutter/cupertino.dart'; class ApplicationPreferences { bool enableDarkMode; bool forceMobileMode; + bool showPerformancesOverlay; ApplicationPreferences({ @required this.enableDarkMode, @required this.forceMobileMode, + @required this.showPerformancesOverlay, }) : assert(enableDarkMode != null), - assert(forceMobileMode != null); + assert(forceMobileMode != null), + assert(showPerformancesOverlay != null); } diff --git a/lib/ui/routes/settings/application_settings.dart b/lib/ui/routes/settings/application_settings.dart index 5918b5d..232350f 100644 --- a/lib/ui/routes/settings/application_settings.dart +++ b/lib/ui/routes/settings/application_settings.dart @@ -67,6 +67,8 @@ class _ApplicationSettingsState extends State { SettingsSection _buildDebugSection() => SettingsSection( title: tr("Debug features"), tiles: [ + + // Force mobile mode _PreferencesSettingsTile( preferencesKey: PreferencesKeyList.FORCE_MOBILE_MODE, title: tr("Force mobile mode"), @@ -75,6 +77,15 @@ class _ApplicationSettingsState extends State { onChange: _updatedSettings, helper: _preferencesHelper, ), + + // Show performances overlay + _PreferencesSettingsTile( + preferencesKey: PreferencesKeyList.SHOW_PERFORMANCE_OVERLAY, + title: tr("Show performances overlay"), + subtitle: null, + onChange: _updatedSettings, + helper: _preferencesHelper, + ), ], );