From 7f29131867949dce6501f89821b1b987da31a9cf Mon Sep 17 00:00:00 2001 From: surya-technovert Date: Mon, 10 Jun 2024 16:29:25 +0530 Subject: [PATCH] Added OnLifeCycleChange for theme. --- lib/ui/theme/dynamic_theme_builder.dart | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/ui/theme/dynamic_theme_builder.dart b/lib/ui/theme/dynamic_theme_builder.dart index 5ee0a22212..2c1ec87b2d 100644 --- a/lib/ui/theme/dynamic_theme_builder.dart +++ b/lib/ui/theme/dynamic_theme_builder.dart @@ -2,6 +2,7 @@ import 'dart:ui'; import 'package:dynamic_color/dynamic_color.dart'; import 'package:dynamic_themes/dynamic_themes.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:revanced_manager/app/app.router.dart'; @@ -24,14 +25,26 @@ class DynamicThemeBuilder extends StatefulWidget { class _DynamicThemeBuilderState extends State with WidgetsBindingObserver { - Brightness brightness = PlatformDispatcher.instance.platformBrightness; + late Brightness _currentBrightness; @override void initState() { super.initState(); + _currentBrightness = PlatformDispatcher.instance.platformBrightness; WidgetsBinding.instance.addObserver(this); } + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + if (state == AppLifecycleState.resumed) { + final systemBrightness = PlatformDispatcher.instance.platformBrightness; + if (_currentBrightness != systemBrightness) { + _currentBrightness = systemBrightness; + setState(() {}); + } + } + } + @override Widget build(BuildContext context) { return DynamicColorBuilder( @@ -66,10 +79,10 @@ class _DynamicThemeBuilderState extends State return DynamicTheme( themeCollection: ThemeCollection( themes: { - 0: brightness == Brightness.light + 0: _currentBrightness == Brightness.light ? lightCustomTheme : darkCustomTheme, - 1: brightness == Brightness.light + 1: _currentBrightness == Brightness.light ? lightDynamicTheme : darkDynamicTheme, 2: lightCustomTheme,