2023-09-21 02:25:23 +02:00
|
|
|
import 'dart:ui';
|
2022-09-05 04:32:36 +02:00
|
|
|
import 'package:dynamic_color/dynamic_color.dart';
|
|
|
|
import 'package:dynamic_themes/dynamic_themes.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2023-09-21 02:25:23 +02:00
|
|
|
import 'package:flutter/services.dart';
|
2022-09-05 04:32:36 +02:00
|
|
|
import 'package:google_fonts/google_fonts.dart';
|
2023-09-21 02:25:23 +02:00
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
2022-09-05 04:32:36 +02:00
|
|
|
import 'package:revanced_manager/app/app.router.dart';
|
2023-09-21 02:25:23 +02:00
|
|
|
import 'package:revanced_manager/services/manager_api.dart';
|
2022-09-05 04:32:36 +02:00
|
|
|
import 'package:revanced_manager/theme.dart';
|
|
|
|
import 'package:stacked_services/stacked_services.dart';
|
|
|
|
|
2023-09-21 02:25:23 +02:00
|
|
|
class DynamicThemeBuilder extends StatefulWidget {
|
2022-09-05 04:32:36 +02:00
|
|
|
const DynamicThemeBuilder({
|
2023-11-11 13:07:32 +01:00
|
|
|
super.key,
|
2022-09-05 04:32:36 +02:00
|
|
|
required this.title,
|
|
|
|
required this.home,
|
|
|
|
required this.localizationsDelegates,
|
2023-11-11 13:07:32 +01:00
|
|
|
});
|
2023-01-30 13:35:06 +01:00
|
|
|
final String title;
|
|
|
|
final Widget home;
|
|
|
|
final Iterable<LocalizationsDelegate> localizationsDelegates;
|
2022-09-05 04:32:36 +02:00
|
|
|
|
2023-09-21 02:25:23 +02:00
|
|
|
@override
|
|
|
|
State<DynamicThemeBuilder> createState() => _DynamicThemeBuilderState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _DynamicThemeBuilderState extends State<DynamicThemeBuilder> with WidgetsBindingObserver {
|
|
|
|
Brightness brightness = PlatformDispatcher.instance.platformBrightness;
|
|
|
|
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
WidgetsBinding.instance.addObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void didChangePlatformBrightness() {
|
|
|
|
setState(() {
|
|
|
|
brightness = PlatformDispatcher.instance.platformBrightness;
|
|
|
|
});
|
|
|
|
if (_managerAPI.getThemeMode() < 2) {
|
|
|
|
SystemChrome.setSystemUIOverlayStyle(
|
|
|
|
SystemUiOverlayStyle(
|
|
|
|
systemNavigationBarIconBrightness:
|
|
|
|
brightness == Brightness.light ? Brightness.dark : Brightness.light,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-05 04:32:36 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return DynamicColorBuilder(
|
|
|
|
builder: (lightColorScheme, darkColorScheme) {
|
2023-01-30 13:35:06 +01:00
|
|
|
final ThemeData lightDynamicTheme = ThemeData(
|
2022-09-05 04:32:36 +02:00
|
|
|
useMaterial3: true,
|
2022-09-06 19:07:23 +02:00
|
|
|
navigationBarTheme: NavigationBarThemeData(
|
|
|
|
labelTextStyle: MaterialStateProperty.all(
|
2022-09-07 13:01:04 +02:00
|
|
|
GoogleFonts.roboto(
|
2023-02-07 13:46:29 +01:00
|
|
|
color: lightColorScheme?.onSurface,
|
2022-09-06 19:07:23 +02:00
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-09-05 04:32:36 +02:00
|
|
|
colorScheme: lightColorScheme?.harmonized(),
|
|
|
|
textTheme: GoogleFonts.robotoTextTheme(ThemeData.light().textTheme),
|
|
|
|
);
|
2023-01-30 13:35:06 +01:00
|
|
|
final ThemeData darkDynamicTheme = ThemeData(
|
2022-09-05 04:32:36 +02:00
|
|
|
useMaterial3: true,
|
2022-09-06 19:07:23 +02:00
|
|
|
navigationBarTheme: NavigationBarThemeData(
|
|
|
|
labelTextStyle: MaterialStateProperty.all(
|
2022-09-07 13:01:04 +02:00
|
|
|
GoogleFonts.roboto(
|
2023-02-07 13:46:29 +01:00
|
|
|
color: darkColorScheme?.onSurface,
|
2022-09-06 19:07:23 +02:00
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-09-05 04:32:36 +02:00
|
|
|
colorScheme: darkColorScheme?.harmonized(),
|
|
|
|
textTheme: GoogleFonts.robotoTextTheme(ThemeData.dark().textTheme),
|
|
|
|
);
|
|
|
|
return DynamicTheme(
|
|
|
|
themeCollection: ThemeCollection(
|
|
|
|
themes: {
|
2023-09-21 02:25:23 +02:00
|
|
|
0: brightness == Brightness.light ? lightCustomTheme : darkCustomTheme,
|
|
|
|
1: brightness == Brightness.light ? lightDynamicTheme : darkDynamicTheme,
|
|
|
|
2: lightCustomTheme,
|
|
|
|
3: lightDynamicTheme,
|
|
|
|
4: darkCustomTheme,
|
|
|
|
5: darkDynamicTheme,
|
2022-09-05 04:32:36 +02:00
|
|
|
},
|
2023-09-21 05:03:15 +02:00
|
|
|
fallbackTheme: PlatformDispatcher.instance.platformBrightness == Brightness.light ? lightCustomTheme : darkCustomTheme,
|
2022-09-05 04:32:36 +02:00
|
|
|
),
|
|
|
|
builder: (context, theme) => MaterialApp(
|
2023-09-21 02:25:23 +02:00
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
title: widget.title,
|
|
|
|
navigatorKey: StackedService.navigatorKey,
|
|
|
|
onGenerateRoute: StackedRouter().onGenerateRoute,
|
|
|
|
theme: theme,
|
|
|
|
home: widget.home,
|
|
|
|
localizationsDelegates: widget.localizationsDelegates,
|
|
|
|
),
|
2022-09-05 04:32:36 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2023-09-21 02:25:23 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
super.dispose();
|
|
|
|
}
|
2023-02-19 04:16:49 +01:00
|
|
|
}
|