fix: native status bar theming

This commit is contained in:
2025-09-05 21:38:10 +02:00
parent 57d6c503f2
commit 975c9c5a08
6 changed files with 35 additions and 48 deletions

View File

@@ -136,15 +136,19 @@ void initTheme(AppInitialization data) {
.activeIndex) {
case 1:
appStyle = lightStyle;
isLightMode.value = true;
break;
case 2:
appStyle = darkStyle;
isLightMode.value = false;
break;
default:
if (brightness == Brightness.dark) {
appStyle = darkStyle;
isLightMode.value = true;
} else {
appStyle = lightStyle;
isLightMode.value = false;
}
}
}
@@ -243,6 +247,8 @@ void main() async {
});
}
final ValueNotifier<bool> isLightMode = ValueNotifier<bool>(true);
class InitializationScreen extends StatelessWidget {
InitializationScreen({super.key});
@@ -335,7 +341,30 @@ class InitializationScreen extends StatelessWidget {
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: AppLocalizations.supportedLocales,
home: DefaultAssetBundle(bundle: FirkaBundle(), child: screen),
home: DefaultAssetBundle(
bundle: FirkaBundle(),
child: ValueListenableBuilder<bool>(
valueListenable: isLightMode,
builder: (context, isLight, _) {
final overlay = SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness:
isLight ? Brightness.dark : Brightness.light,
statusBarBrightness:
isLight ? Brightness.light : Brightness.dark,
systemStatusBarContrastEnforced: false,
);
// Ensure system is updated immediately
SystemChrome.setSystemUIOverlayStyle(overlay);
return AnnotatedRegion<SystemUiOverlayStyle>(
value: overlay,
child: screen,
);
},
),
),
routes: {
'/login': (context) => DefaultAssetBundle(
bundle: FirkaBundle(),

View File

@@ -116,8 +116,10 @@ class FirkaColors {
class FirkaStyle {
FirkaColors colors;
FirkaFonts fonts;
bool isLight;
FirkaStyle({required this.colors, required this.fonts});
FirkaStyle(
{required this.isLight, required this.colors, required this.fonts});
}
final _defaultFonts = FirkaFonts(
@@ -196,6 +198,7 @@ final _defaultFonts = FirkaFonts(
);
final FirkaStyle lightStyle = FirkaStyle(
isLight: true,
colors: FirkaColors(
background: Color(0xFFFAFFF0),
backgroundAmoled: Colors.black,
@@ -230,6 +233,7 @@ final FirkaStyle lightStyle = FirkaStyle(
fonts: _defaultFonts);
final FirkaStyle darkStyle = FirkaStyle(
isLight: false,
colors: FirkaColors(
background: Color(0xFF0D1202),
backgroundAmoled: Colors.black,

View File

@@ -245,9 +245,6 @@ class _HomeScreenState extends State<HomeScreen> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
_updateSystemUI();
});
widget.data.settingsUpdateNotifier.addListener(settingsUpdateListener);
@@ -280,17 +277,6 @@ class _HomeScreenState extends State<HomeScreen> {
}
}
void _updateSystemUI() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarBrightness: Brightness.light,
statusBarIconBrightness: Brightness.dark,
statusBarColor: Colors.transparent,
systemNavigationBarColor: appStyle.colors.background,
systemNavigationBarIconBrightness: Brightness.dark,
systemNavigationBarDividerColor: Colors.transparent,
));
}
void _onRefresh() async {
late void Function() finishListener;
finishListener = () {
@@ -310,8 +296,6 @@ class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
_updateSystemUI(); // Update system UI on every build, to compensate for the android system being dumb
if (!widget.data.settings.group("settings").boolean("beta_warning")) {
Timer.run(() {
Navigator.of(context).pushAndRemoveUntil(
@@ -580,8 +564,6 @@ class _HomeScreenState extends State<HomeScreen> {
_pageController.dispose();
super.dispose();
widget.data.settingsUpdateNotifier.removeListener(settingsUpdateListener);
_disposed = true;
_fetching = false;
_prefetched = false;

View File

@@ -31,12 +31,6 @@ class _LoginScreenState extends State<LoginScreen> {
_loginWebView = LoginWebviewWidget(widget.data);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
statusBarBrightness: Brightness.light,
statusBarIconBrightness: Brightness.dark,
statusBarColor: Colors.transparent,
systemNavigationBarColor: Color(0xFFFAFFF0),
));
_preloadImages();
}

View File

@@ -33,9 +33,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
_updateSystemUI();
});
activeIcon = widget.data.settings
.group("settings")
@@ -44,17 +41,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
.iconString("icon_picker");
}
void _updateSystemUI() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarBrightness: Brightness.light,
statusBarIconBrightness: Brightness.dark,
statusBarColor: Colors.transparent,
systemNavigationBarColor: appStyle.colors.background,
systemNavigationBarIconBrightness: Brightness.dark,
systemNavigationBarDividerColor: Colors.transparent,
));
}
List<Widget> createWidgetTree(
Iterable<SettingsItem> items, SettingsStore settings,
{bool forceRender = false}) {
@@ -506,8 +492,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
@override
Widget build(BuildContext context) {
_updateSystemUI(); // Update system UI on every build, to compensate for the android system being dumb
var body = createWidgetTree(widget.items.values, widget.data.settings);
return Scaffold(

View File

@@ -96,12 +96,6 @@ class _WearLoginScreenState extends State<WearLoginScreen> {
}));
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
statusBarBrightness: Brightness.light,
statusBarIconBrightness: Brightness.dark,
statusBarColor: Colors.transparent,
systemNavigationBarColor: Color(0xFFDAE4F7),
));
}
@override