Answers for "No MediaQuery widget ancestor found."

3

No MediaQuery widget ancestor found.

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
0

no mediaquery widget ancestor found. flutter

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp();
  }
}
Posted by: Guest on September-01-2021

Code answers related to "No MediaQuery widget ancestor found."

Code answers related to "TypeScript"

Browse Popular Code Answers by Language