From 5d7f2c68c66aa9c7ed7ab9ee8675214a54fe55df Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Sat, 29 Oct 2022 14:22:19 +0200 Subject: [PATCH] Fixed issue theme color defined by system --- .../settings/customization/customization.dart | 61 ++++++++++++------- .../customization/theme_mode_button.dart | 41 ++++++++++--- lib/widgets/servers_list/servers_list.dart | 4 +- 3 files changed, 74 insertions(+), 32 deletions(-) diff --git a/lib/screens/settings/customization/customization.dart b/lib/screens/settings/customization/customization.dart index 48f641c..e428873 100644 --- a/lib/screens/settings/customization/customization.dart +++ b/lib/screens/settings/customization/customization.dart @@ -45,7 +45,7 @@ class _CustomizationWidgetState extends State { @override void initState() { - selectedTheme = widget.appConfigProvider.selectedTheme == ThemeMode.light ? 1 : 2; + selectedTheme = widget.appConfigProvider.selectedThemeNumber; dynamicColor = widget.appConfigProvider.useDynamicColor; selectedColor = widget.appConfigProvider.staticColor; useThemeColorInsteadGreenRed = widget.appConfigProvider.useThemeColorForStatus; @@ -62,29 +62,47 @@ class _CustomizationWidgetState extends State { ), body: ListView( children: [ - SectionLabel(label: AppLocalizations.of(context)!.theme), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, + SectionLabel( + label: AppLocalizations.of(context)!.theme, + padding: const EdgeInsets.only(top: 10, left: 25, right: 25, bottom: 5), + ), + Column( children: [ - ThemeModeButton( - icon: Icons.light_mode, - value: 1, - selected: selectedTheme, - label: AppLocalizations.of(context)!.light, + CustomSwitchListTile( + value: selectedTheme == 0 ? true : false, onChanged: (value) { - selectedTheme = value; - appConfigProvider.setSelectedTheme(value); - } + selectedTheme = value == true ? 0 : 1; + appConfigProvider.setSelectedTheme(value == true ? 0 : 1); + }, + title: AppLocalizations.of(context)!.systemDefined, ), - ThemeModeButton( - icon: Icons.dark_mode, - value: 2, - selected: selectedTheme, - label: AppLocalizations.of(context)!.dark, - onChanged: (value) { - selectedTheme = value; - appConfigProvider.setSelectedTheme(value); - } + const SizedBox(height: 10), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + ThemeModeButton( + icon: Icons.light_mode, + value: 1, + selected: selectedTheme, + label: AppLocalizations.of(context)!.light, + onChanged: (value) { + selectedTheme = value; + appConfigProvider.setSelectedTheme(value); + }, + disabled: selectedTheme == 0 ? true : false, + ), + ThemeModeButton( + icon: Icons.dark_mode, + value: 2, + selected: selectedTheme, + label: AppLocalizations.of(context)!.dark, + onChanged: (value) { + selectedTheme = value; + appConfigProvider.setSelectedTheme(value); + }, + disabled: selectedTheme == 0 ? true : false, + ), + ], ), ], ), @@ -100,6 +118,7 @@ class _CustomizationWidgetState extends State { }, title: AppLocalizations.of(context)!.useDynamicTheme, ), + if (!(appConfigProvider.androidDeviceInfo != null && appConfigProvider.androidDeviceInfo!.version.sdkInt! >= 31)) const SizedBox(height: 20), if (dynamicColor == false) ...[ SizedBox( width: MediaQuery.of(context).size.width, diff --git a/lib/screens/settings/customization/theme_mode_button.dart b/lib/screens/settings/customization/theme_mode_button.dart index 74b1a28..8b0ee70 100644 --- a/lib/screens/settings/customization/theme_mode_button.dart +++ b/lib/screens/settings/customization/theme_mode_button.dart @@ -6,6 +6,7 @@ class ThemeModeButton extends StatelessWidget { final int selected; final String label; final void Function(int) onChanged; + final bool? disabled; const ThemeModeButton({ Key? key, @@ -14,15 +15,25 @@ class ThemeModeButton extends StatelessWidget { required this.selected, required this.label, required this.onChanged, + this.disabled }) : super(key: key); @override Widget build(BuildContext context) { + final Color greyBackgroundColor = Theme.of(context).brightness == Brightness.light + ?const Color.fromRGBO(200, 200, 200, 1) + :const Color.fromRGBO(50, 50, 50, 1); + final Color greyIconColor = Theme.of(context).brightness == Brightness.light + ? const Color.fromRGBO(130, 130, 130, 1) + : const Color.fromRGBO(100, 100, 100, 1); + return Material( color: Colors.transparent, borderRadius: BorderRadius.circular(16), child: InkWell( - onTap: () => onChanged(value), + onTap: disabled == null || disabled == false + ? () => onChanged(value) + : null, borderRadius: BorderRadius.circular(16), child: AnimatedContainer( padding: const EdgeInsets.all(10), @@ -32,10 +43,16 @@ class ThemeModeButton extends StatelessWidget { decoration: BoxDecoration( borderRadius: BorderRadius.circular(16), color: value == selected - ? Theme.of(context).primaryColor - : Theme.of(context).primaryColor.withOpacity(0.1), + ? disabled == null || disabled == false + ? Theme.of(context).primaryColor + : greyBackgroundColor + : disabled == null || disabled == false + ? Theme.of(context).primaryColor.withOpacity(0.1) + : greyBackgroundColor, border: Border.all( - color: Theme.of(context).primaryColor + color: disabled == null || disabled == false + ? Theme.of(context).primaryColor + : greyBackgroundColor ) ), child: Column( @@ -44,16 +61,24 @@ class ThemeModeButton extends StatelessWidget { Icon( icon, color: value == selected - ? Theme.of(context).primaryColor.computeLuminance() > 0.5 ? Colors.black : Colors.white - : null, + ? disabled == null || disabled == false + ? Theme.of(context).primaryColor.computeLuminance() > 0.5 ? Colors.black : Colors.white + : greyIconColor + : disabled == null || disabled == false + ? null + : greyIconColor, size: 30, ), Text( label, style: TextStyle( color: value == selected - ? Theme.of(context).primaryColor.computeLuminance() > 0.5 ? Colors.black : Colors.white - : null, + ? disabled == null || disabled == false + ? Theme.of(context).primaryColor.computeLuminance() > 0.5 ? Colors.black : Colors.white + : greyIconColor + : disabled == null || disabled == false + ? null + : greyIconColor, fontSize: 18 ), ) diff --git a/lib/widgets/servers_list/servers_list.dart b/lib/widgets/servers_list/servers_list.dart index e329abf..55805d9 100644 --- a/lib/widgets/servers_list/servers_list.dart +++ b/lib/widgets/servers_list/servers_list.dart @@ -51,9 +51,7 @@ class _ServersListState extends State with SingleTickerProviderStat duration: const Duration(milliseconds: 200), vsync: this, ) - ..addListener(() { - setState(() {}); - }); + ..addListener(() => setState(() => {})); animation = Tween( begin: 0.0, end: 0.5,