Answers for "MyApp widgets require a MediaQuery widget ancestor."

3

MyApp widgets require a MediaQuery widget ancestor.

Its because, the showModalBottomSheet tries to access the ancestor of type 
MaterialApp from the given context.

Use Builder widget to get new context with MaterialApp ancestor or Separate 
your MaterialAapp and Scaffold widgets into separate widgets.

Using Builder :

floatingActionButton: Builder(
  builder: (context) => FloatingActionButton(
      child: Icon(Icons.add),
      onPressed: () { showModalBottomSheet(
          context: context,
          builder: (context) {
            return Text('Modal bottom sheet', style: TextStyle(fontSize: 30));
          });
      }
  ),
),
  
reference:
https://stackoverflow.com/questions/59864150/flutter-exception-caught-by-gesture-no-mediaquery-widget-found-inside-showmodal
Posted by: Guest on March-01-2021

Code answers related to "MyApp widgets require a MediaQuery widget ancestor."

Code answers related to "TypeScript"

Browse Popular Code Answers by Language