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:
David Adegoke
2025-05-29 16:46:43 +03:00
committed by GitHub
parent b79fb6af1f
commit b77c22b0df
3 changed files with 15 additions and 26 deletions
+13
View File
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:io';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cake_wallet/core/auth_service.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
Widget build(BuildContext context) {
// this only happens when the app has been in the background for some time