Skip to content

Commit

Permalink
Use EdgeToEdge ui overlay mode on Android (#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
pohuing authored Nov 7, 2024
1 parent 64ec52f commit 775b1fc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ import 'services/jellyfin_api_helper.dart';
import 'services/locale_helper.dart';
import 'services/music_player_background_task.dart';
import 'services/theme_mode_helper.dart';
import 'services/ui_overlay_setter_observer.dart';
import 'setup_logging.dart';

void main() async {
// If the app has failed, this is set to true. If true, we don't attempt to run the main app since the error app has started.
bool hasFailed = false;
try {
await setupLogging();
await _setupEdgeToEdgeOverlayStyle();
await setupHive();
_migrateDownloadLocations();
_migrateSortOptions();
Expand Down Expand Up @@ -119,6 +121,15 @@ void main() async {
}
}

Future<void> _setupEdgeToEdgeOverlayStyle() async {
if (Platform.isAndroid) {
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(systemNavigationBarColor: Colors.transparent));
final binding = WidgetsFlutterBinding.ensureInitialized();
binding.addObserver(UIOverlaySetterObserver());
}
}

Future<void> _setupJellyfinApiData() async {
GetIt.instance.registerSingleton(JellyfinApiHelper());
}
Expand Down
20 changes: 20 additions & 0 deletions lib/services/ui_overlay_setter_observer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class UIOverlaySetterObserver extends WidgetsBindingObserver {
@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
switch (state) {
case AppLifecycleState.resumed:
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
systemNavigationBarColor: Colors.transparent,
),
);
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
break;
default:
break;
}
}
}

0 comments on commit 775b1fc

Please sign in to comment.