3

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(),
);
4

2 回答 2

5

改为使用builderMaterialApp这样您就MediaQuery可以MatetialAppTheme.

new MaterialApp(
  builder: (context, child) {
    return new Theme(
      data: getTheme(MediaQuery.of(context)),
      child: child,
    );
  },
  home: new ChatScreen(),
),
于 2018-04-19T08:38:17.147 回答
3
return new MaterialApp(
      title: 'Flutter Demo',
      theme: getTheme(new MediaQueryData.fromWindow(ui.window)),
      home: new Container(),
    );

谢谢君特 :)

于 2018-04-18T05:44:08.060 回答