mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
feat: Apply dark/light mode to system navigation bar too
This commit is contained in:
parent
5d296038b7
commit
9f58757caf
@ -1,6 +1,7 @@
|
|||||||
// ignore_for_file: use_build_context_synchronously
|
// ignore_for_file: use_build_context_synchronously
|
||||||
import 'package:dynamic_themes/dynamic_themes.dart';
|
import 'package:dynamic_themes/dynamic_themes.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:injectable/injectable.dart';
|
import 'package:injectable/injectable.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:revanced_manager/services/root_api.dart';
|
import 'package:revanced_manager/services/root_api.dart';
|
||||||
@ -15,14 +16,21 @@ class NavigationViewModel extends IndexTrackingViewModel {
|
|||||||
void initialize(BuildContext context) async {
|
void initialize(BuildContext context) async {
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
if (prefs.getBool('useDarkTheme') == null) {
|
if (prefs.getBool('useDarkTheme') == null) {
|
||||||
if (MediaQuery.of(context).platformBrightness == Brightness.light) {
|
bool isDark =
|
||||||
await prefs.setBool('useDarkTheme', false);
|
MediaQuery.of(context).platformBrightness != Brightness.light;
|
||||||
DynamicTheme.of(context)!.setTheme(0);
|
await prefs.setBool('useDarkTheme', isDark);
|
||||||
} else {
|
await DynamicTheme.of(context)!.setTheme(isDark ? 1 : 0);
|
||||||
await prefs.setBool('useDarkTheme', true);
|
|
||||||
DynamicTheme.of(context)!.setTheme(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
SystemChrome.setSystemUIOverlayStyle(
|
||||||
|
SystemUiOverlayStyle(
|
||||||
|
systemNavigationBarColor:
|
||||||
|
DynamicTheme.of(context)!.theme.colorScheme.surface,
|
||||||
|
systemNavigationBarIconBrightness:
|
||||||
|
DynamicTheme.of(context)!.theme.brightness == Brightness.light
|
||||||
|
? Brightness.dark
|
||||||
|
: Brightness.light,
|
||||||
|
),
|
||||||
|
);
|
||||||
RootAPI().hasRootPermissions();
|
RootAPI().hasRootPermissions();
|
||||||
Permission.requestInstallPackages.request();
|
Permission.requestInstallPackages.request();
|
||||||
Permission.ignoreBatteryOptimizations.request();
|
Permission.ignoreBatteryOptimizations.request();
|
||||||
|
@ -3,6 +3,7 @@ import 'dart:io';
|
|||||||
import 'package:device_info_plus/device_info_plus.dart';
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
import 'package:dynamic_themes/dynamic_themes.dart';
|
import 'package:dynamic_themes/dynamic_themes.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||||
import 'package:logcat/logcat.dart';
|
import 'package:logcat/logcat.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
@ -50,10 +51,16 @@ class SettingsViewModel extends BaseViewModel {
|
|||||||
await _managerAPI.setUseDynamicTheme(value);
|
await _managerAPI.setUseDynamicTheme(value);
|
||||||
int currentTheme = DynamicTheme.of(context)!.themeId;
|
int currentTheme = DynamicTheme.of(context)!.themeId;
|
||||||
if (currentTheme.isEven) {
|
if (currentTheme.isEven) {
|
||||||
DynamicTheme.of(context)!.setTheme(value ? 2 : 0);
|
await DynamicTheme.of(context)!.setTheme(value ? 2 : 0);
|
||||||
} else {
|
} else {
|
||||||
DynamicTheme.of(context)!.setTheme(value ? 3 : 1);
|
await DynamicTheme.of(context)!.setTheme(value ? 3 : 1);
|
||||||
}
|
}
|
||||||
|
SystemChrome.setSystemUIOverlayStyle(
|
||||||
|
SystemUiOverlayStyle(
|
||||||
|
systemNavigationBarColor:
|
||||||
|
DynamicTheme.of(context)!.theme.colorScheme.surface,
|
||||||
|
),
|
||||||
|
);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,10 +72,18 @@ class SettingsViewModel extends BaseViewModel {
|
|||||||
await _managerAPI.setUseDarkTheme(value);
|
await _managerAPI.setUseDarkTheme(value);
|
||||||
int currentTheme = DynamicTheme.of(context)!.themeId;
|
int currentTheme = DynamicTheme.of(context)!.themeId;
|
||||||
if (currentTheme < 2) {
|
if (currentTheme < 2) {
|
||||||
DynamicTheme.of(context)!.setTheme(value ? 1 : 0);
|
await DynamicTheme.of(context)!.setTheme(value ? 1 : 0);
|
||||||
} else {
|
} else {
|
||||||
DynamicTheme.of(context)!.setTheme(value ? 3 : 2);
|
await DynamicTheme.of(context)!.setTheme(value ? 3 : 2);
|
||||||
}
|
}
|
||||||
|
SystemChrome.setSystemUIOverlayStyle(
|
||||||
|
SystemUiOverlayStyle(
|
||||||
|
systemNavigationBarColor:
|
||||||
|
DynamicTheme.of(context)!.theme.colorScheme.surface,
|
||||||
|
systemNavigationBarIconBrightness:
|
||||||
|
value ? Brightness.light : Brightness.dark,
|
||||||
|
),
|
||||||
|
);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user