搜索插件、代码仓与 APP 分类

status_bar_control 封面
插件详情v4.0.0

status_bar_control

状态栏控制,可让您在 iOS 和 Android 上控制状态栏的颜色、样式(主题)、可见性以及透明属性。

AndroidiOS
近 30 天下载
700
喜欢数
91
Pub 分数
140

安装插件

flutter pub add status_bar_control

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

状态栏控制是一个Flutter包,可让开发者在Android和iOS平台上自定义状态栏。它允许控制状态栏的颜色、外观(浅色或深色主题)、可见性以及透明度。该包提供了一个简单且一致的API来管理状态栏属性,确保用户界面体验更加精致。它与原生平台功能无缝配合,并支持两种移动操作系统。适用于需要根据上下文或主题变化动态调整状态栏的应用。

适合场景

  • 按屏幕自定义状态栏颜色
  • 调整状态栏样式以适应深色/浅色主题
  • 临时隐藏状态栏
  • 使状态栏透明
  • 管理全屏应用中的状态栏

主要特点

  • 跨平台支持(iOS 和 Android)
  • 对颜色、样式、可见性和透明度的控制
  • 简单直观的 API
  • 与原生平台行为兼容
  • 无需额外的原生代码

适合对象

  • 需要动态状态栏样式的应用
  • 开发沉浸式用户界面的开发者
  • 具有多个主题的项目
  • 全屏或游戏式界面
  • 具有复杂导航状态的应用程序

使用建议

  • 需要正确处理平台特定的行为
  • 可能需要额外配置以处理边缘情况
  • 仅限状态栏自定义
  • 不适用于高级系统级修改
  • 取决于Flutter生命周期事件的正确使用

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Status Bar Control

Flutter_Tests

Since flutter_statusbar_manager is no longer maintained, this package is a re-publish and will be occasionally updated for continued use in existing projects.

Buy Me A Coffee      

About

Status Bar Control, lets you control the status bar color, style (theme), visibility, and translucent properties across iOS and Android. With some added bonus for Android to control the Navigation Bar.

This plugin is based on React Native's StatusBar component.

The Navigation Bar code was taken from the awesome flutter-screen-theme-plugin.

The plugin was tested with iOS 15 and Android 12 (API 31).

Last Updates
  • v3.2.0 rename to status_bar_control and re-publish to pub.dev
  • v3.1.2 add cutout-mode for Android and SafeArea to demo app
  • v3.1.1 resolve UIOverlay-deprecations and update of demo app
  • v3.1.0 support for Android V2 thanks to jWinterDay and rafaelmaeuer
  • v3.0.1 compatible with flutter web thanks to rafaelmaeuer
  • v3.0.0 support for null safety thanks to NarHakobyan
  • v2.0.0 compatible with AndroidX thanks to lorenzOliveto

See CHANGELOG for a complete list of changes.

Examples

Build the example project for iOS and Android from the example folder.

Android
Status Bar Color Status Bar Hide Navigation Bar
Demo App Android Status Bar Demo App Android Status Bar hide Demo App Android Nav Bar
iOS
Demo Iphone 8 Demo Iphone X
Demo App Iphone 8 Demo App Iphone X

Note: not all of the shown examples might still work in the latest versions of Android or iOS

Installation

status_bar_control: ^3.2.1

to your pubspec.yaml and run

flutter pub get

in your project's root directory.

Basic Usage

Create a new project with command

flutter create myapp

On iOS add the following in your Info.plist (if not already present):

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

On Android add the following in your styles.xml (cutout-mode for API >27):

<item name="android:windowLayoutInDisplayCutoutMode" tools:targetApi="o_mr1">shortEdges</item>

Import the plugin in lib/main.dart like this:

import 'package:status_bar_control/status_bar_control.dart';

Methods

setColor
Platforms: Android

The setColor method will set the status bar background color. On iOS the method will always return a successful Future.

Parameter Type Default Required Description
color Color none Yes The color to be set as background, can use colors with opacity.
animated bool false No Whether or not to animate the color change.
await StatusBarControl.setColor(Colors.green, animated:true);
setTranslucent
Platforms: Android

The setTranslucent method will set the status bar translucent status. On iOS the methods will always return a successful Future.

Parameter Type Default Required Description
translucent bool none Yes Whether or not the status bar will be translucent.
await StatusBarControl.setTranslucent(true);
setHidden
Platforms: Android, iOS

The setHidden will hide the status bar.

Parameter Type Default Required Description
hidden bool none Yes Whether or not to hide the status bar.
animation StatusBarAnimation StatusBarAnimation.NONE No The hiding animation to use (iOS only).
await StatusBarControl.setHidden(true, animation:StatusBarAnimation.SLIDE);
setStyle
Platforms: Android, iOS

The setStyle method will set the status bar theme.

Parameter Type Default Required Description
style StatusBarStyle none Yes The status bar theme to use for styling, can either be light, dark, default.
await StatusBarControl.setStyle(StatusBarStyle.DARK_CONTENT);
setNetworkActivityIndicatorVisible
Platforms: iOS

The setNetworkActivityIndicatorVisible method will show or hide the activity indicator, On Android the method will always return a successful Future.

Parameter Type Default Required Description
visible bool none Yes Whether or not to show the activity indicator.
await StatusBarControl.setNetworkActivityIndicatorVisible(true);
getHeight
Platforms: Android, iOS

The getHeight getter method will return the height of the status bar.

double height = await StatusBarControl.getHeight

Bonus Methods

setNavigationBarColor
Platforms: Android

The setNavigationBarColor method will set the navigation bar background color. On iOS the method will always return a successful Future.

Parameter Type Default Required Description
color Color none Yes The color to be set as background.
animated bool false No Whether or not to animate the color change.
await StatusBarControl.setNavigationBarColor(Colors.green, animated:true);
setNavigationBarStyle
Platforms: Android

The setNavigationBarStyle method will set the navigation bar theme.

Parameter Type Default Required Description
style NavigationBarStyle none Yes The navigation bar theme to use for styling, can either be light, dark, default.
await StatusBarControl.setNavigationBarStyle(NavigationBarStyle.DARK);
setFullscreen
Platforms: Android, iOS

The setFullscreen method will set the app in fullscreen mode.

Parameter Type Default Required Description
fullscreen bool none Yes Whether or not to set the app on fullscreen mode.
await StatusBarControl.setNavigationBarStyle(NavigationBarStyle.DARK);

Enums

StatusBarStyle
  • StatusBarStyle.DEFAULT
  • StatusBarStyle.LIGHT_CONTENT
  • StatusBarStyle.DARK_CONTENT
StatusBarAnimation
  • StatusBarAnimation.NONE
  • StatusBarAnimation.FADE
  • StatusBarAnimation.SLIDE
NavigationBarStyle
  • NavigationBarStyle.DEFAULT
  • NavigationBarStyle.DARK
  • NavigationBarStyle.LIGHT

Status bar

Compatibility: Android (6.0+) & iOS

On Android, it will only work with Android 6.0 (Marshmallow) and above devices.

Navigation bar

Compatibility: Android only

Android 5.0 (Lollipop) and above: color

Android 8.0 (Oreo) and above: style (dark/light)

所属分类

源码仓库

使用此插件的项目