我MediaQuery.of() called with a context that does not contain a MediaQuery.
在尝试从以下位置访问 MediaQuery 时得到MaterialApp
:
return new MaterialApp(
title: 'Flutter Demo',
theme: getTheme(MediaQuery.of(context)),
home: new Container(),
);
我MediaQuery.of() called with a context that does not contain a MediaQuery.
在尝试从以下位置访问 MediaQuery 时得到MaterialApp
:
return new MaterialApp(
title: 'Flutter Demo',
theme: getTheme(MediaQuery.of(context)),
home: new Container(),
);
改为使用builder
。MaterialApp
这样您就MediaQuery
可以MatetialApp
在Theme
.
new MaterialApp(
builder: (context, child) {
return new Theme(
data: getTheme(MediaQuery.of(context)),
child: child,
);
},
home: new ChatScreen(),
),
return new MaterialApp(
title: 'Flutter Demo',
theme: getTheme(new MediaQueryData.fromWindow(ui.window)),
home: new Container(),
);
谢谢君特 :)