Skip to content

Commit

Permalink
Added OnLifeCycleChange for theme.
Browse files Browse the repository at this point in the history
  • Loading branch information
surya-technovert committed Jun 10, 2024
1 parent e0a6de2 commit 7f29131
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/ui/theme/dynamic_theme_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -24,14 +25,26 @@ class DynamicThemeBuilder extends StatefulWidget {

class _DynamicThemeBuilderState extends State<DynamicThemeBuilder>
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(
Expand Down Expand Up @@ -66,10 +79,10 @@ class _DynamicThemeBuilderState extends State<DynamicThemeBuilder>
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,
Expand Down

0 comments on commit 7f29131

Please sign in to comment.