본문 바로가기

개인 공부

[플러터] 에러..예외가 발생했습니다.

728x90

예외가 발생했습니다.
FlutterError (No MediaQuery widget ancestor found.
MyApp widgets require a MediaQuery widget ancestor.
The specific widget that could not find a MediaQuery ancestor was:
  MyApp
The ownership chain for the affected widget is: "MyApp ← [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.)

미디어 쿼리 사용 후 계속 이런 에러가 발생했다...

조상중에 MaterialApp 이 있어야 한다는 뜻을 제대로 이해못했나보다 ...

해당 내용을 받아오기 위해 

  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
라고 작성되어있던 코드를

  Widget build(BuildContext context) {
    return MaterialApp(
      home: Builder(builder: (BuildContext context) {
        return Scaffold(
          appBar: AppBar(

로 수정하였다.

context 값을 제대로 못받아와서 발생한 에러였구나 ...

728x90
댓글