[英]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.