fix(welcome): defer doc-load to didChangeDependencies
Some checks failed
Security / Security check (push) Failing after 2s
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:
parent
e9538b66b7
commit
0cf3b0ed72
1 changed files with 8 additions and 4 deletions
|
|
@ -935,12 +935,16 @@ class _DocReaderSheet extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _DocReaderSheetState extends State<_DocReaderSheet> {
|
||||
late final Future<String> _content;
|
||||
Future<String>? _content;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_content = _load();
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
// `_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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue