fix(welcome): defer doc-load to didChangeDependencies
Some checks failed
Security / Security check (push) Failing after 2s

_DocReaderSheetState.initState() called _load(), which
synchronously calls Localizations.localeOf(context) before any
await. That triggers dependOnInheritedWidgetOfExactType<
_LocalizationsScope>() in initState(), which Flutter forbids
because InheritedWidget wiring is not finished yet.

Symptom (clicking a doc card in Welcome):
  dependOnInheritedWidgetOfExactType<_LocalizationsScope>()
  or dependOnInheritedElement() was called before
  _DocReaderSheetState.initState() completed.

Fix: defer _load() to didChangeDependencies(), which runs
after initState() and after InheritedWidget hookup. Gate on
_content == null so it runs exactly once per widget lifetime
(didChangeDependencies can also fire on later dependency
changes; we only want the first load).

Signed-off-by: flemming-it <stefan.a.flemming@googlemail.com>
This commit is contained in:
flemming-it 2026-05-23 17:47:23 +02:00
parent e9538b66b7
commit 0cf3b0ed72

View file

@ -935,12 +935,16 @@ class _DocReaderSheet extends StatefulWidget {
} }
class _DocReaderSheetState extends State<_DocReaderSheet> { class _DocReaderSheetState extends State<_DocReaderSheet> {
late final Future<String> _content; Future<String>? _content;
@override @override
void initState() { void didChangeDependencies() {
super.initState(); super.didChangeDependencies();
_content = _load(); // `_load()` needs `Localizations.localeOf(context)`. That call
// touches InheritedWidgets which aren't safe to read in
// initState() must wait until didChangeDependencies. We
// gate on `_content == null` so it runs exactly once.
_content ??= _load();
} }
Future<String> _load() async { Future<String> _load() async {