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';
|
2024-02-12 00:22:25 +01:00
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
2022-09-05 04:32:36 +02:00
|
|
|
import 'package:google_fonts/google_fonts.dart';
|
|
|
|
import 'package:revanced_manager/app/app.router.dart';
|
2024-02-12 00:22:25 +01:00
|
|
|
import 'package:revanced_manager/gen/strings.g.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,
|
2023-11-11 13:07:32 +01:00
|
|
|
});
|
2023-01-30 13:35:06 +01:00
|
|
|
final String title;
|
|
|
|
final Widget home;
|
2022-09-05 04:32:36 +02:00
|
|
|
|
2023-09-21 02:25:23 +02:00
|
|
|
@override
|
|
|
|
State<DynamicThemeBuilder> createState() => _DynamicThemeBuilderState();
|
|
|
|
}
|
|
|
|
|
2023-12-23 04:47:12 +01:00
|
|
|
class _DynamicThemeBuilderState extends State<DynamicThemeBuilder>
|
|
|
|
with WidgetsBindingObserver {
|
2023-09-21 02:25:23 +02:00
|
|
|
Brightness brightness = PlatformDispatcher.instance.platformBrightness;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
WidgetsBinding.instance.addObserver(this);
|
|
|
|
}
|
|
|
|
|
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(
|
2024-02-25 03:37:55 +01:00
|
|
|
brightness: Brightness.dark,
|
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-12-23 04:47:12 +01:00
|
|
|
0: brightness == Brightness.light
|
|
|
|
? lightCustomTheme
|
|
|
|
: darkCustomTheme,
|
|
|
|
1: brightness == Brightness.light
|
|
|
|
? lightDynamicTheme
|
|
|
|
: darkDynamicTheme,
|
2023-09-21 02:25:23 +02:00
|
|
|
2: lightCustomTheme,
|
|
|
|
3: lightDynamicTheme,
|
|
|
|
4: darkCustomTheme,
|
|
|
|
5: darkDynamicTheme,
|
2022-09-05 04:32:36 +02:00
|
|
|
},
|
2023-12-23 04:47:12 +01:00
|
|
|
fallbackTheme: PlatformDispatcher.instance.platformBrightness ==
|
|
|
|
Brightness.light
|
|
|
|
? lightCustomTheme
|
|
|
|
: darkCustomTheme,
|
2022-09-05 04:32:36 +02:00
|
|
|
),
|
|
|
|
builder: (context, theme) => MaterialApp(
|
2023-12-23 04:47:12 +01:00
|
|
|
debugShowCheckedModeBanner: false,
|
|
|
|
title: widget.title,
|
|
|
|
navigatorKey: StackedService.navigatorKey,
|
|
|
|
onGenerateRoute: StackedRouter().onGenerateRoute,
|
|
|
|
theme: theme,
|
|
|
|
home: widget.home,
|
2024-02-12 00:22:25 +01:00
|
|
|
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
|
|
|
locale: TranslationProvider.of(context).flutterLocale,
|
|
|
|
supportedLocales: AppLocaleUtils.supportedLocales,
|
2023-12-23 04:47:12 +01:00
|
|
|
),
|
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
|
|
|
}
|