From 7f29131867949dce6501f89821b1b987da31a9cf Mon Sep 17 00:00:00 2001 From: surya-technovert Date: Mon, 10 Jun 2024 16:29:25 +0530 Subject: [PATCH 1/3] 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, From b6214175a0add55dd3b152a7e6e1bc4c314595ba Mon Sep 17 00:00:00 2001 From: surya-technovert Date: Mon, 10 Jun 2024 16:51:48 +0530 Subject: [PATCH 2/3] Revert "Added OnLifeCycleChange for theme." This reverts commit 7f29131867949dce6501f89821b1b987da31a9cf. --- lib/ui/theme/dynamic_theme_builder.dart | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/ui/theme/dynamic_theme_builder.dart b/lib/ui/theme/dynamic_theme_builder.dart index 2c1ec87b2d..5ee0a22212 100644 --- a/lib/ui/theme/dynamic_theme_builder.dart +++ b/lib/ui/theme/dynamic_theme_builder.dart @@ -2,7 +2,6 @@ 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'; @@ -25,26 +24,14 @@ class DynamicThemeBuilder extends StatefulWidget { class _DynamicThemeBuilderState extends State with WidgetsBindingObserver { - late Brightness _currentBrightness; + Brightness brightness = PlatformDispatcher.instance.platformBrightness; @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( @@ -79,10 +66,10 @@ class _DynamicThemeBuilderState extends State return DynamicTheme( themeCollection: ThemeCollection( themes: { - 0: _currentBrightness == Brightness.light + 0: brightness == Brightness.light ? lightCustomTheme : darkCustomTheme, - 1: _currentBrightness == Brightness.light + 1: brightness == Brightness.light ? lightDynamicTheme : darkDynamicTheme, 2: lightCustomTheme, From f817c9c5705994b7ac04d4f26e2701ccb35b99d1 Mon Sep 17 00:00:00 2001 From: surya-technovert Date: Mon, 10 Jun 2024 16:57:05 +0530 Subject: [PATCH 3/3] feat: added theme update on applifeCycleState Change/Resume --- lib/ui/theme/dynamic_theme_builder.dart | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ui/theme/dynamic_theme_builder.dart b/lib/ui/theme/dynamic_theme_builder.dart index 5ee0a22212..c704761778 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 brightness; @override void initState() { super.initState(); + brightness = PlatformDispatcher.instance.platformBrightness; WidgetsBinding.instance.addObserver(this); } + @override + void didChangeAppLifecycleState(AppLifecycleState state) { + if (state == AppLifecycleState.resumed) { + final systemBrightness = PlatformDispatcher.instance.platformBrightness; + if (brightness != systemBrightness) { + brightness = systemBrightness; + setState(() {}); + } + } + } + @override Widget build(BuildContext context) { return DynamicColorBuilder(