简体   繁体   English

MediaQuery.of()使用不包含MediaQuery的上下文调用

[英]MediaQuery.of() called with a context that does not contain a MediaQuery

Why do am I getting this Error??? 为什么我得到这个错误???

Isn't the Mediaquery provided by the MaterialApp? 不是MaterialApp提供的Mediaquery吗? I don't quite understand. 我不太明白。

class Test extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: themeBuilder(context),
      home: Scaffold(
        appBar: AppBar(
          title: Text('Title'),
        ),
        body: Container(
          alignment: Alignment.center,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                'All their equipment and instruments are alive.',
              ),
              Text(
                'All their equipment and instruments are alive.',
                style: TextStyle(
                  fontSize: 34,
                  fontWeight: FontWeight.w700,
                ),
              ),
              GradientButton(
                child: Text('click me!'),
                onPressed: () {},
                width: MediaQuery.of(context).size.width,
              ),
              TextField()
            ],
          ),
        ),
      ),
    );
  }
}

I don't know what is it I am doing wrong here. 我不知道这是什么我在这里做错了。 It worked just fine before. 它之前工作得很好。

class Test extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
  return MaterialApp(
   title: Text('Title'),
   theme: themeBuilder(context),
   home: HomePage(),
  );
 }
}

class HomePage extends StatelessWidget {
 @override
 Widget build(BuildContext context) {
   final size = MediaQuery.of(context).size;

   return Container(
     child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[

         ...

         GradientButton(
            child: Text('click me!'),
            onPressed: () {},
            width: MediaQuery.of(context).size.width,
          ),
         ]
     ),
   );
 }
}

Try this and lemme know how it goes 试试这个,然后知道它是怎么回事

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用不包含 MediaQuery 的上下文调用 MediaQuery.of() - MediaQuery.of() called with a context that does not contain MediaQuery Flutter 错误:使用不包含 MediaQuery 的上下文调用 MediaQuery.of() - Flutter Error: MediaQuery.of() called with a context that does not contain a MediaQuery 使用不包含 MediaQuery 的上下文调用 MediaQuery.of()。 (紧急援助) - MediaQuery.of() called with a context that does not contain a MediaQuery. (emergency aid) 使用不包含 MediaQuery 的上下文调用 MediaQuery.of()。 错误 - MediaQuery.of() called with a context that does not contain a MediaQuery. error 使用不包含 MediaQuery 的上下文(来自 MaterialApp)调用 MediaQuery.of() - MediaQuery.of() called with a context (from MaterialApp) that does not contain a MediaQuery 在使用不包含 MediaQuery 的上下文调用的 flutter MediaQuery.of() 中出现错误 - Getting Error in flutter MediaQuery.of() called with a context that does not contain a MediaQuery 使用上下文调用的 Mediaquery.of 不包含 mediaquery 错误 - Mediaquery.of called with a context does not contain a mediaquery error 在 MaterialApp 内部。 使用不包含 MediaQuery 的上下文调用 MediaQuery.of() - Inside of MatterialApp. MediaQuery.of() called with a context that does not contain a MediaQuery (使用不包含 MediaQuery 的上下文调用 MediaQuery.of()。)错误 - (MediaQuery.of() called with a context that does not contain a MediaQuery.) error MaterialApp 和“使用不包含 MediaQuery 的上下文调用的 MediaQuery.of()” - MaterialApp and "MediaQuery.of() called with a context that does not contain a MediaQuery"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM