Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Fix Theme.of(context) called in initState on RMAB webview screen

Barnabase3fc26146f7a
diff --git a/lib/screens/admin_rmab_screen.dart b/lib/screens/admin_rmab_screen.dart
index 6f59686e..e45d41d0 100644
--- a/lib/screens/admin_rmab_screen.dart
+++ b/lib/screens/admin_rmab_screen.dart
@@ -12,6 +12,7 @@ class AdminRmabScreen extends StatefulWidget {
class _AdminRmabScreenState extends State<AdminRmabScreen> {
late final WebViewController _controller;
+ bool _bgApplied = false;
int _progress = 0;
bool _failed = false;
@@ -20,7 +21,6 @@ class _AdminRmabScreenState extends State<AdminRmabScreen> {
super.initState();
_controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
- ..setBackgroundColor(Theme.of(context).colorScheme.surface)
..setNavigationDelegate(NavigationDelegate(
onProgress: (p) => mounted ? setState(() => _progress = p) : null,
onPageStarted: (_) => mounted ? setState(() => _failed = false) : null,
@@ -33,6 +33,15 @@ class _AdminRmabScreenState extends State<AdminRmabScreen> {
..loadRequest(Uri.parse(widget.url));
}
+ @override
+ void didChangeDependencies() {
+ super.didChangeDependencies();
+ if (!_bgApplied) {
+ _bgApplied = true;
+ _controller.setBackgroundColor(Theme.of(context).colorScheme.surface);
+ }
+ }
+
@override
Widget build(BuildContext context) {
final cs = Theme.of(context).colorScheme;