无法隐藏状态栏 - Flutter - 此表达式的类型为 'void',因此无法使用其值

Unable to hide status bar - Flutter - This expression has a type of 'void' so its value can't be used

在 setSystemUIOverlayStyle 上看到以下错误。

我是否必须向 pubspec.yaml 添加一些包?

错误:

尝试下面的代码我认为你写错了代码。更多参考

void main() {
  SystemChrome.setSystemUIOverlayStyle(
    SystemUiOverlayStyle(
      statusBarColor: Colors.red,//change color on your need
    ),
  );
  runApp(const MyApp());
}

结果屏幕->

您可以通过在 main():

中添加以下内容来设置 StatusBar 透明
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent));

问题 是你把它放在 你的 runApp() 里面。 您的 main() 应如下所示:

void main() {
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
        statusBarColor: Colors.transparent));
runApp(const MyApp());
}

您可以将此添加到您的 initState() 方法中。这是隐藏底部导航,因为 well.It 用于全屏设计。

@覆盖 无效初始化状态(){ super.initState();

 SystemChrome.setEnabledSystemUIMode(
  SystemUiMode.manual,
  overlays: [],
);}