Whenever I turn off DevicePreview, I throw an exception:
dependOnInheritedWidgetOfExactType() or dependOnInheritedElement() was called before _ScreenUtilInitState.initState() completed.
When an inherited widget changes, for example if the value of Theme.of() changes, its dependent widgets are rebuilt. If the dependent widget's reference to the inherited widget is in a constructor or an initState() method, then the rebuilt dependent widget will not reflect the changes in the inherited widget.
Typically references to inherited widgets should occur in widget build() methods. Alternatively, initialization based on inherited widgets can be placed in the didChangeDependencies method, which is called after initState and whenever the dependencies change thereafter.
Whenever I turn off DevicePreview, I throw an exception:
dependOnInheritedWidgetOfExactType() or dependOnInheritedElement() was called before _ScreenUtilInitState.initState() completed.
When an inherited widget changes, for example if the value of Theme.of() changes, its dependent widgets are rebuilt. If the dependent widget's reference to the inherited widget is in a constructor or an initState() method, then the rebuilt dependent widget will not reflect the changes in the inherited widget.
Typically references to inherited widgets should occur in widget build() methods. Alternatively, initialization based on inherited widgets can be placed in the didChangeDependencies method, which is called after initState and whenever the dependencies change thereafter.
screenutil_init.dart ↓
I tried to change the code at
initState
and the problem was solved, but I'm not sure if it was the right change.