mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
Update Theme Setup (#2300)
* refactor(theme-setup-update): Move didChangePlatformBrightness lifecycle method to Root widget instead of AppState. We already have an active WidgetsBindingObserver in Root widget. * fix(theme): Add workaround for flutter iOS didChangePlatformBrightness issue causing unneeded rebuilds.
This commit is contained in:
parent
b79fb6af1f
commit
b77c22b0df
3 changed files with 15 additions and 26 deletions
|
@ -25,7 +25,6 @@ import 'package:cake_wallet/routes.dart';
|
||||||
import 'package:cake_wallet/src/screens/root/root.dart';
|
import 'package:cake_wallet/src/screens/root/root.dart';
|
||||||
import 'package:cake_wallet/store/app_store.dart';
|
import 'package:cake_wallet/store/app_store.dart';
|
||||||
import 'package:cake_wallet/store/authentication_store.dart';
|
import 'package:cake_wallet/store/authentication_store.dart';
|
||||||
import 'package:cake_wallet/themes/core/material_base_theme.dart';
|
|
||||||
import 'package:cake_wallet/themes/utils/theme_provider.dart';
|
import 'package:cake_wallet/themes/utils/theme_provider.dart';
|
||||||
import 'package:cake_wallet/utils/device_info.dart';
|
import 'package:cake_wallet/utils/device_info.dart';
|
||||||
import 'package:cake_wallet/utils/exception_handler.dart';
|
import 'package:cake_wallet/utils/exception_handler.dart';
|
||||||
|
@ -290,30 +289,7 @@ class App extends StatefulWidget {
|
||||||
AppState createState() => AppState();
|
AppState createState() => AppState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppState extends State<App> with SingleTickerProviderStateMixin, WidgetsBindingObserver {
|
class AppState extends State<App> with SingleTickerProviderStateMixin {
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
WidgetsBinding.instance.addObserver(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
WidgetsBinding.instance.removeObserver(this);
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didChangePlatformBrightness() {
|
|
||||||
final appStore = getIt.get<AppStore>();
|
|
||||||
if (appStore.themeStore.themeMode == ThemeMode.system) {
|
|
||||||
final systemTheme = appStore.themeStore.getThemeFromSystem();
|
|
||||||
if (appStore.themeStore.currentTheme != systemTheme) {
|
|
||||||
appStore.themeStore.setTheme(systemTheme);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Observer(
|
return Observer(
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||||
import 'package:cake_wallet/core/auth_service.dart';
|
import 'package:cake_wallet/core/auth_service.dart';
|
||||||
import 'package:cake_wallet/core/totp_request_details.dart';
|
import 'package:cake_wallet/core/totp_request_details.dart';
|
||||||
|
@ -159,6 +160,18 @@ class RootState extends State<Root> with WidgetsBindingObserver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangePlatformBrightness() {
|
||||||
|
if (widget.appStore.themeStore.themeMode == ThemeMode.system) {
|
||||||
|
Future.delayed(Duration(milliseconds: Platform.isIOS ? 500 : 0), () {
|
||||||
|
final systemTheme = widget.appStore.themeStore.getThemeFromSystem();
|
||||||
|
if (widget.appStore.themeStore.currentTheme != systemTheme) {
|
||||||
|
widget.appStore.themeStore.setTheme(systemTheme);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// this only happens when the app has been in the background for some time
|
// this only happens when the app has been in the background for some time
|
||||||
|
|
|
@ -168,7 +168,7 @@ abstract class ThemeStoreBase with Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialThemeBase getThemeFromSystem() {
|
MaterialThemeBase getThemeFromSystem() {
|
||||||
final systemBrightness = WidgetsBinding.instance.window.platformBrightness;
|
final systemBrightness = WidgetsBinding.instance.platformDispatcher.platformBrightness;
|
||||||
return systemBrightness == Brightness.dark ? ThemeList.darkTheme : ThemeList.lightTheme;
|
return systemBrightness == Brightness.dark ? ThemeList.darkTheme : ThemeList.lightTheme;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue