【问题标题】:Why status bar of my app hide automatically?为什么我的应用程序的状态栏会自动隐藏?
【发布时间】:2020-04-11 21:39:04
【问题描述】:

我启动了一个 Flutter 应用,并向该应用添加了一些代码,然后,当我在 android 设备上运行我的应用时,我的应用的状态栏会自动隐藏?

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primaryColor: Colors.black,
        accentColor: Colors.amber,
        appBarTheme: AppBarTheme(
          textTheme: ThemeData.light().textTheme.copyWith(
                title: TextStyle(
                  color: Colors.amber,
                  fontFamily: 'OpenSans',
                  fontSize: 20,
                  fontWeight: FontWeight.bold,
                ),
              ),
        ),
      ),
      title: 'Currency App',
      home: HomePage(),
      routes: {
        ExchangePage.routeName: (ctx) => ExchangePage(),
        GrowsPage.routeName: (ctx) => GrowsPage(),
        CurrencyPage.routeName: (ctx) => CurrencyPage(),
        ReorderListItemScreen.routeName: (ctx) => ReorderListItemScreen(),
      },
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    _portraitModeOnly();
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        iconTheme: IconThemeData(color: Colors.amber),
        title: const Text('Currency App'),
      ),
      body: ImageCarousel(),
      drawer: DrawerCode(),
    );
  }

  void _portraitModeOnly() {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]);
  }
}

这是我的代码,我搜索了很多网站,但没有找到合适的,请帮助我,谢谢

【问题讨论】:

    标签: android flutter statusbar


    【解决方案1】:

    我的应用也遇到了同样的问题。

    全屏应用,没有状态栏。

    你应该尝试在AndroidManifest.xml中找到你加载的Theme

    就我而言,我正在加载一些 styles.xml 像这样:

    <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
         <item name="android:windowBackground">@drawable/launch_background</item>
         <item name="android:windowFullscreen">true</item>
    </style>
    

    我将此条目更改为 false

    <item name="android:windowFullscreen">false</item>
    

    【讨论】:

      【解决方案2】:

      StatusBar 不会去任何地方,你看不到它的唯一原因是你有primaryColor black,这会将 AppBar 和 StatusBar 更改为相同的颜色,所以它看起来就像消失了一样。如果您想独立更改状态栏颜色,您可以这样做:

      import 'package:flutter/services.dart';  
      
        @override
        Widget build(BuildContext context) {
      
          SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( statusBarColor: Colors.lightBlue ));
      
          return MaterialApp()
      

      另外,'title' 属性已被弃用,appBarTheme: AppBarTheme() 内部的那个 使用“标题”之一https://api.flutter.dev/flutter/material/TextTheme-class.html

      【讨论】:

      • 你好Unbreachable,我想你错了,我说的是状态栏,但你说的是AppBar,状态栏显示电池的百分比,没有AppBar 谢谢(-:
      • 哦,哎呀,所以你是说它以某种方式消失了?如果更改 primaryColor 的颜色,则 StatusBar 和 AppBar 都会更改为该颜色。你想让他们与众不同吗?
      • 你的回答不正确,状态栏被隐藏了,我改了颜色还是不行(-:
      • 你的颜色是黑色的,它不会用那种颜色显示。如果将其更改为灰色,您将能够在状态栏上看到较暗的阴影
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-18
      • 2014-01-29
      • 1970-01-01
      • 2013-10-01
      • 2014-10-30
      • 2011-02-23
      • 2014-11-26
      相关资源
      最近更新 更多