mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
feat: Auto dark mode based on system theme
This commit is contained in:
parent
85cd176347
commit
598f7571de
@ -76,7 +76,7 @@ class DynamicThemeBuilder extends StatelessWidget {
|
||||
2: lightDynamicTheme,
|
||||
3: darkDynamicTheme,
|
||||
},
|
||||
fallbackTheme: darkCustomTheme,
|
||||
fallbackTheme: lightCustomTheme,
|
||||
),
|
||||
builder: (context, theme) => MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
|
@ -11,6 +11,7 @@ class NavigationView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<NavigationViewModel>.reactive(
|
||||
onModelReady: (model) => model.initialize(context),
|
||||
viewModelBuilder: () => locator<NavigationViewModel>(),
|
||||
builder: (context, model, child) => Scaffold(
|
||||
body: PageTransitionSwitcher(
|
||||
|
@ -1,12 +1,28 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'package:dynamic_themes/dynamic_themes.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:revanced_manager/ui/views/home/home_view.dart';
|
||||
import 'package:revanced_manager/ui/views/patcher/patcher_view.dart';
|
||||
import 'package:revanced_manager/ui/views/settings/settings_view.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
@lazySingleton
|
||||
class NavigationViewModel extends IndexTrackingViewModel {
|
||||
void initialize(BuildContext context) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
if (prefs.getBool('useDarkTheme') == null) {
|
||||
if (MediaQuery.of(context).platformBrightness == Brightness.light) {
|
||||
await prefs.setBool('useDarkTheme', false);
|
||||
DynamicTheme.of(context)!.setTheme(0);
|
||||
} else {
|
||||
await prefs.setBool('useDarkTheme', true);
|
||||
DynamicTheme.of(context)!.setTheme(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Widget getViewForIndex(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
|
Loading…
Reference in New Issue
Block a user