为什么我的应用程序的状态栏会自动隐藏?

问题描述 投票:0回答:1

我启动了一个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个回答
-1
投票

StatusBar不会走到任何地方,您看不到的唯一原因是您拥有primaryColor黑色,这会将AppBar和StatusBar更改为相同的颜色,因此看起来就消失了。如果要独立更改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

之一
© www.soinside.com 2019 - 2024. All rights reserved.