From ea71a97e4520e87249dec1db35f06f06bcc6f97d Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sun, 16 Feb 2020 20:11:39 +0100 Subject: [PATCH] Clean up dark mode --- lib/components/adaptive_page_layout.dart | 2 +- lib/components/list_items/chat_list_item.dart | 2 +- ...ThemeSwitcher.dart => theme_switcher.dart} | 63 +++++++++---------- lib/main.dart | 2 +- lib/views/chat_details.dart | 28 ++++++--- lib/views/chat_list.dart | 2 +- lib/views/settings.dart | 11 +++- lib/views/settings_themes.dart | 4 +- 8 files changed, 65 insertions(+), 49 deletions(-) rename lib/components/{ThemeSwitcher.dart => theme_switcher.dart} (83%) diff --git a/lib/components/adaptive_page_layout.dart b/lib/components/adaptive_page_layout.dart index 218a5af..1351a68 100644 --- a/lib/components/adaptive_page_layout.dart +++ b/lib/components/adaptive_page_layout.dart @@ -38,7 +38,7 @@ class AdaptivePageLayout extends StatelessWidget { ), Container( width: 1, - color: Color(0xFFE8E8E8), + color: Theme.of(context).secondaryHeaderColor, //Color(0xFFE8E8E8), ), Expanded( child: Container( diff --git a/lib/components/list_items/chat_list_item.dart b/lib/components/list_items/chat_list_item.dart index 09bb54f..65d4d80 100644 --- a/lib/components/list_items/chat_list_item.dart +++ b/lib/components/list_items/chat_list_item.dart @@ -11,7 +11,7 @@ import '../../utils/date_time_extension.dart'; import '../../utils/event_extension.dart'; import '../../utils/room_extension.dart'; import '../../views/chat.dart'; -import '../ThemeSwitcher.dart'; +import '../theme_switcher.dart'; import '../avatar.dart'; import '../dialogs/simple_dialogs.dart'; import '../matrix.dart'; diff --git a/lib/components/ThemeSwitcher.dart b/lib/components/theme_switcher.dart similarity index 83% rename from lib/components/ThemeSwitcher.dart rename to lib/components/theme_switcher.dart index 3b0ed15..6f87518 100644 --- a/lib/components/ThemeSwitcher.dart +++ b/lib/components/theme_switcher.dart @@ -1,7 +1,5 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; - -import '../utils/famedlysdk_store.dart'; import 'matrix.dart'; enum Themes { @@ -49,6 +47,16 @@ final ThemeData darkTheme = ThemeData.dark().copyWith( scaffoldBackgroundColor: Color(0xff121212), accentColor: Color(0xFFF5B4D2), secondaryHeaderColor: Color(0xff1D1D1D), + dialogTheme: DialogTheme( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.0), + ), + ), + popupMenuTheme: PopupMenuThemeData( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.0), + ), + ), appBarTheme: AppBarTheme( brightness: Brightness.dark, color: Color(0xff1D1D1D), @@ -70,6 +78,16 @@ final ThemeData amoledTheme = ThemeData.dark().copyWith( scaffoldBackgroundColor: Colors.black, accentColor: Color(0xFFF5B4D2), secondaryHeaderColor: Color(0xff1D1D1D), + dialogTheme: DialogTheme( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.0), + ), + ), + popupMenuTheme: PopupMenuThemeData( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.0), + ), + ), appBarTheme: AppBarTheme( brightness: Brightness.dark, color: Color(0xff1D1D1D), @@ -141,25 +159,15 @@ class ThemeSwitcherWidgetState extends State { BuildContext context; Future loadSelection(MatrixState matrix) async { - if (kIsWeb) { - Store store = matrix.client.storeAPI; - String item = await store.getItem("theme") ?? "light"; - selectedTheme = - Themes.values.firstWhere((e) => e.toString() == 'Themes.' + item); + String item = await matrix.client.storeAPI.getItem("theme") ?? "light"; + selectedTheme = + Themes.values.firstWhere((e) => e.toString() == 'Themes.' + item); - amoledEnabled = - (await store.getItem("amoled_enabled") ?? "false").toLowerCase() == - 'true'; - } else { - ExtendedStore store = matrix.client.storeAPI; - String item = await store.getItem("theme") ?? "light"; - selectedTheme = - Themes.values.firstWhere((e) => e.toString() == 'Themes.' + item); + amoledEnabled = + (await matrix.client.storeAPI.getItem("amoled_enabled") ?? "false") + .toLowerCase() == + 'true'; - amoledEnabled = - (await store.getItem("amoled_enabled") ?? "false").toLowerCase() == - 'true'; - } switchTheme(matrix, selectedTheme, amoledEnabled); return; } @@ -205,23 +213,12 @@ class ThemeSwitcherWidgetState extends State { } Future saveThemeValue(MatrixState matrix, Themes value) async { - if (kIsWeb) { - Store store = matrix.client.storeAPI; - await store.setItem("theme", value.toString().split('.').last); - } else { - ExtendedStore store = matrix.client.storeAPI; - await store.setItem("theme", value.toString().split('.').last); - } + await matrix.client.storeAPI + .setItem("theme", value.toString().split('.').last); } Future saveAmoledEnabledValue(MatrixState matrix, bool value) async { - if (kIsWeb) { - Store store = matrix.client.storeAPI; - await store.setItem("amoled_enabled", value.toString()); - } else { - ExtendedStore store = matrix.client.storeAPI; - await store.setItem("amoled_enabled", value.toString()); - } + await matrix.client.storeAPI.setItem("amoled_enabled", value.toString()); } void setup() async { diff --git a/lib/main.dart b/lib/main.dart index 6db3d11..ed4d557 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,7 +5,7 @@ import 'package:flutter_localizations/flutter_localizations.dart'; import 'i18n/i18n.dart'; import 'views/sign_up.dart'; -import 'components/ThemeSwitcher.dart'; +import 'components/theme_switcher.dart'; import 'components/matrix.dart'; import 'views/chat_list.dart'; diff --git a/lib/views/chat_details.dart b/lib/views/chat_details.dart index 72b4f45..e006d4b 100644 --- a/lib/views/chat_details.dart +++ b/lib/views/chat_details.dart @@ -202,7 +202,12 @@ class _ChatDetailsState extends State { ChatSettingsPopupMenu(widget.room, false) ], title: Text(widget.room.getLocalizedDisplayname(context), - style: TextStyle(color: Colors.black)), + style: TextStyle( + color: Theme.of(context) + .appBarTheme + .textTheme + .headline6 + .color)), backgroundColor: Theme.of(context).appBarTheme.color, flexibleSpace: FlexibleSpaceBar( background: ContentBanner(widget.room.avatar, @@ -221,7 +226,8 @@ class _ChatDetailsState extends State { ListTile( leading: widget.room.canSendEvent("m.room.topic") ? CircleAvatar( - backgroundColor: Colors.white, + backgroundColor: + Theme.of(context).scaffoldBackgroundColor, foregroundColor: Colors.grey, child: Icon(Icons.edit), ) @@ -257,7 +263,8 @@ class _ChatDetailsState extends State { if (widget.room.canSendEvent("m.room.name")) ListTile( leading: CircleAvatar( - backgroundColor: Colors.white, + backgroundColor: + Theme.of(context).scaffoldBackgroundColor, foregroundColor: Colors.grey, child: Icon(Icons.people), ), @@ -270,7 +277,8 @@ class _ChatDetailsState extends State { widget.room.joinRules == JoinRules.public) ListTile( leading: CircleAvatar( - backgroundColor: Colors.white, + backgroundColor: + Theme.of(context).scaffoldBackgroundColor, foregroundColor: Colors.grey, child: Icon(Icons.link), ), @@ -284,7 +292,8 @@ class _ChatDetailsState extends State { PopupMenuButton( child: ListTile( leading: CircleAvatar( - backgroundColor: Colors.white, + backgroundColor: + Theme.of(context).scaffoldBackgroundColor, foregroundColor: Colors.grey, child: Icon(Icons.public)), title: Text( @@ -316,7 +325,8 @@ class _ChatDetailsState extends State { PopupMenuButton( child: ListTile( leading: CircleAvatar( - backgroundColor: Colors.white, + backgroundColor: + Theme.of(context).scaffoldBackgroundColor, foregroundColor: Colors.grey, child: Icon(Icons.visibility), ), @@ -363,7 +373,8 @@ class _ChatDetailsState extends State { PopupMenuButton( child: ListTile( leading: CircleAvatar( - backgroundColor: Colors.white, + backgroundColor: + Theme.of(context).scaffoldBackgroundColor, foregroundColor: Colors.grey, child: Icon(Icons.info_outline), ), @@ -436,7 +447,8 @@ class _ChatDetailsState extends State { title: Text(I18n.of(context).loadCountMoreParticipants( (actualMembersCount - members.length).toString())), leading: CircleAvatar( - backgroundColor: Colors.white, + backgroundColor: + Theme.of(context).scaffoldBackgroundColor, child: Icon( Icons.refresh, color: Colors.grey, diff --git a/lib/views/chat_list.dart b/lib/views/chat_list.dart index 373e938..20eaf92 100644 --- a/lib/views/chat_list.dart +++ b/lib/views/chat_list.dart @@ -8,7 +8,7 @@ import 'package:flutter_speed_dial/flutter_speed_dial.dart'; import 'package:toast/toast.dart'; import 'package:uni_links/uni_links.dart'; -import '../components/ThemeSwitcher.dart'; +import '../components/theme_switcher.dart'; import '../components/adaptive_page_layout.dart'; import '../components/list_items/chat_list_item.dart'; import '../components/matrix.dart'; diff --git a/lib/views/settings.dart b/lib/views/settings.dart index 8abe59c..31d2593 100644 --- a/lib/views/settings.dart +++ b/lib/views/settings.dart @@ -114,8 +114,15 @@ class _SettingsState extends State { pinned: true, backgroundColor: Theme.of(context).appBarTheme.color, flexibleSpace: FlexibleSpaceBar( - title: Text(I18n.of(context).settings, - style: TextStyle(color: Colors.black)), + title: Text( + I18n.of(context).settings, + style: TextStyle( + color: Theme.of(context) + .appBarTheme + .textTheme + .headline6 + .color), + ), background: ContentBanner( profile?.avatarUrl ?? MxContent(""), height: 300, diff --git a/lib/views/settings_themes.dart b/lib/views/settings_themes.dart index 0e20faa..c8cb7bf 100644 --- a/lib/views/settings_themes.dart +++ b/lib/views/settings_themes.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import '../components/ThemeSwitcher.dart'; +import '../components/theme_switcher.dart'; import '../components/adaptive_page_layout.dart'; import '../components/matrix.dart'; import '../i18n/i18n.dart'; @@ -82,7 +82,7 @@ class ThemesSettingsState extends State { }); }, ), - Divider(thickness: 8), + Divider(thickness: 1), ListTile( title: Text( I18n.of(context).useAmoledTheme,