MediaQuery Widget Ancestry Issue with ScreenUtil after Flutter upgrade

Viewed 333

I just updated to the latest Flutter stable (2.10). In my main.dart file, I initialize the ScreenUtil package to scale fonts and proportions. I'm guessing the latest update exposed a flaw in my code to begin with, but now after I run the build, I get an error about No MediaQuery widget ancestor being found. I'm struggling to determine the amount of refactoring my entire code might need as a result, so I'd love to get some input.

Here is the error:

======== Exception caught by widgets library 
=======================================================
The following assertion was thrown building Builder(dirty, dependencies: 
[_InheritedProviderScope<ThemeNotifier>]):
No MediaQuery widget ancestor found.

LayoutBuilder widgets require a MediaQuery widget ancestor.
The specific widget that could not find a MediaQuery ancestor was: LayoutBuilder
renderObject: _RenderLayoutBuilder#04ff4
The ownership chain for the affected widget is: "LayoutBuilder ← ScreenUtilInit ← 
_InheritedProviderScope<ThemeNotifier> ← ChangeNotifierProvider<ThemeNotifier> ← 
_NestedHook ← MultiProvider ← [root]"

No MediaQuery ancestor could be found starting from the context that was passed to 
MediaQuery.of(). This can happen because you have not added a WidgetsApp, 
CupertinoApp, or MaterialApp widget (those widgets introduce a MediaQuery), or it can 
happen if the context you use comes from a widget above those widgets.

The relevant error-causing widget was: 
Builder 
Builder:file:///Users/nicklangan/StudioProjects/wtfda_radioland/lib/main.dart:40:23
When the exception was thrown, this was the stack: 
#0      debugCheckHasMediaQuery.<anonymous closure> 
(package:flutter/src/widgets/debug.dart:230:7)

Here, meanwhile, is my main.dart file:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SharedPreferences prefs = await SharedPreferences.getInstance();
   if (prefs.getInt('onBoard') !=null){
      firstRun = prefs.getInt('onBoard');
 }

await SentryFlutter.init(
      (options) => options.dsn = 'https://blahblah',
  appRunner: () =>
 runApp(
MultiProvider(
  providers: [

    ChangeNotifierProvider(
    create: (_) => ThemeNotifier()),

  ],
  child: ScreenUtilInit(
    designSize: Size(390, 844),
    minTextAdapt: true,
    splitScreenMode: true,
    builder: () =>Builder(
        builder: (ctx) {
          final _theme = ctx.select<ThemeNotifier, bool>((theme) => theme.darkTheme!);

          return MaterialApp(
               theme: _theme ?  dark : light,

initialRoute: '/',
routes: {
'/':  (context) =>
        Scaffold(
        body: HomeScreen(),
            ),
'SearchScreen': (context) =>
        Scaffold(
            body: FacilitySearchStartScreen(activityTitle: 'RadioLand Call Letter Match'),
        ),
'LocationSearchScreen': (context) =>
        Scaffold(
            body: LocationSearchStartScreen(activityTitle: 'North American FM Dial Generator'),
        ),

Any help is supremely appreciated, with thanks!

0 Answers
Related