简体   繁体   English

更改状态栏颜色(颤振)

[英]Change Status Bar Color (Flutter)

I am trying to change the color of the battery icon, the wifi icon and the clock icon to some dark color, but I am not succeeding.我正在尝试将电池图标、wifi 图标和时钟图标的颜色更改为某种深色,但我没有成功。 Can anyone help me?谁能帮我? Thanks谢谢

void main() {
  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
    statusBarColor: Colors.black,
    statusBarIconBrightness: Brightness.light,
    statusBarBrightness: Brightness.light,
  ));
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: Scaffold(
          appBar: AppBar(
            title: Text(
              'Flutter',
              style: GoogleFonts.poppins(color: Colors.black),
            ),
            elevation: 0,
            backgroundColor: Colors.transparent,
          ),
          extendBodyBehindAppBar: true,
          body: Container(
            child: Center(child: Text("Hello")),
            color: backgroundUL,
          )),
    );
  }
}

Screenshot截屏

instead change the color, i suggest you to wrap your Scaffold with SafeArea widget.而是更改颜色,我建议您使用SafeArea小部件包裹您的Scaffold

 @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: SafeArea(
             child: Scaffold(
                     appBar: AppBar(
                     ......

this will make your widget rendered on safe area on screen.这将使您的小部件呈现在屏幕上的安全区域。

after Flutter Update you can use this property in AppBar To Change Collor status bar在 Flutter 更新之后,您可以在 AppBar 中使用此属性来更改颜色状态栏

      class MyApp extends StatelessWidget {

    const MyApp({super.key});

  

  

    @override

    Widget build(BuildContext context) {

      return MaterialApp(

        title: 'Flutter Demo',

        theme: ThemeData(primarySwatch: Colors.blue),

        home: Scaffold(

            appBar: AppBar(

              systemOverlayStyle: const SystemUiOverlayStyle(

                // Status bar color

                statusBarColor: Colors.red,

                // Status bar brightness (optional)

                statusBarIconBrightness: Brightness.dark,

                // For Android (dark icons)

                statusBarBrightness: Brightness.light, // For iO

              ),

              title: const Text(

                'Flutter',

              ),

              elevation: 0,

              backgroundColor: Colors.transparent,

            ),

            extendBodyBehindAppBar: true,

            body: Container(

              child: const Center(child: Text("Hello")),

            )),

      );

    }

  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM