đ iOS Battery Indicator
A Flutter widget that replicates the native iOS battery indicator, including support for iOS 27 style and automatic system battery monitoring.
Language: English | 䏿
![]() |
![]() |
![]() |
![]() |
|---|
⨠Features
- Native iOS look & feel â faithfully reproduces the iOS battery icon with rounded superellipse shape and proper sizing.
- Automatic system battery â reads battery level, charging state, and low-power mode from the device in real time when no manual value is supplied.
- System event callbacks â
onBatteryLevelChangedandonBatteryStateChangednotify the parent when system values change in auto mode. - Manual control â optionally pass
batteryLevel,batteryState, andisInBatterySaveModefor demo or custom scenarios. - iOS 27 style â supports the new borderless design introduced in iOS 27, with automatic detection of the iOS version.
- Charging bolt overlay â renders a bolt (âĄ) glyph using the native Cupertino icon font when the battery is charging.
- Cutout percentage â in normal discharging mode, the percentage text is punched through the fill using a cutout effect for a polished look.
- Low battery warning â the indicator turns red when the battery level drops below a configurable threshold (10â30, defaults to 20).
- Battery save mode â the track turns yellow when low-power mode is active.
- Real-time save-mode monitoring â
monitorBatterySaveModepolls Low Power Mode (auto mode only; poll interval configurable viasaveModePollInterval, default 30s; supported on Android, iOS, macOS and Windows; not on web or other platforms). - Light / Dark mode â automatically adapts to the ambient
Brightness, or force a specific brightness via thebrightnessproperty. - Smooth animations â animated fill level, color changes, charging bolt
transitions, and crossfade between basic and percentage display. All
animation durations are configurable via
animationDuration. - Charging sound â optionally play the native iOS charging sound
(
connectedToPower) when entering the charging state in manual mode (iOS only).
đ Getting started
Install via pub.dev â pub.dev/packages/ios_battery_indicator/install
Live Demo â try it out online
âī¸ Platform setup
This package depends on battery_plus and device_info_plus. No additional
configuration is required for iOS and macOS. For Android, ensure the
android/app/build.gradle.kts targets API 21 or higher (the default Flutter
template already satisfies this).
đ Usage
đ¤ Auto mode (system battery)
The simplest usage â the widget reads everything from the device:
IosBatteryIndicator();
You can configure how often the system battery level is polled (default 30s):
IosBatteryIndicator(
batteryLevelPollInterval: const Duration(seconds: 15), // level poll interval (default 30s)
);
- Battery percentage display is enabled by default.
- Listen to
Battery.onBatteryStateChangedfor real-time state updates. - Automatically detect iOS 27+ and render the borderless style.
đŽ Manual control
Provide explicit values to bypass the system readings:
IosBatteryIndicator(
batteryLevel: 80,
batteryState: BatteryState.charging,
);
đī¸ Controlling display options
IosBatteryIndicator(
showBatteryPercentage: false, // hide the percentage number
fontFeatures: const [.tabularFigures()], // default: monospaced digits (only effective when showBatteryPercentage is true)
chargingWithBolt: false, // hide the bolt when charging
);
đ Charging sound (iOS only)
When in manual mode, you can play the native iOS charging sound when the
battery state is set to BatteryState.charging:
IosBatteryIndicator(
batteryState: BatteryState.charging,
playChargingSound: true, // play iOS charging sound
);
Note
This feature requires the ios_system_sound
package and is only supported on iOS. It has no effect on the web or other
platforms, and is ignored in auto mode (when batteryState is null).
đ¨ Styling
IosBatteryIndicator(
isIOS27Style: true, // force iOS 27 borderless style
brightness: Brightness.dark, // force dark mode colors
lowBatteryThreshold: 15, // turn red when ⤠15%
animationDuration: const Duration(milliseconds: 500), // slow down animations
);
đ Sizing
Use height orwidth (mutually exclusive) to scale it:
IosBatteryIndicator(height: 36); // 36 logical pixels tall, width auto
IosBatteryIndicator(width: 40); // 40 logical pixels wide, height auto
đĄ Callbacks
Receive real-time system battery updates when in auto mode:
IosBatteryIndicator(
onBatteryLevelChanged: (level) => print('Battery: $level%'),
onBatteryStateChanged: (state) => print('State: $state'),
);
Note
These callbacks only fire when batteryLevel / batteryState is
null (system mode). When providing manual values, use your own state
management instead.
đ Battery save mode monitoring
By default the system Low Power Mode is read only once when the widget
initializes. To keep it in sync when the user toggles it at runtime, enable
monitorBatterySaveMode â this only takes effect when isInBatterySaveMode
is null (system mode). Note this is only supported on Android, iOS, macOS
and Windows â it has no effect on web or other platforms:
IosBatteryIndicator(
isInBatterySaveMode: null, // read from the system
monitorBatterySaveMode: true, // re-poll periodically
saveModePollInterval: const Duration(seconds: 10), // poll interval (default 30s)
);
Note
This has no effect when isInBatterySaveMode is explicitly provided.
đī¸ Custom theme
You can customize the colors by providing a BatteryIndicatorTheme via
ThemeData.extensions:
MaterialApp(
theme: ThemeData(
extensions: [
BatteryIndicatorTheme(
bgColor: CupertinoColors.black.withValues(alpha: .3),
dischargingTrackColor: CupertinoColors.black,
chargingTrackColor: CupertinoColors.activeGreen,
criticallyLowTrackColor: CupertinoColors.destructiveRed,
saveModeTrackColor: CupertinoColors.systemYellow,
contentColor: CupertinoColors.black,
contentAntiColor: CupertinoColors.white,
),
],
),
home: /* ... */,
);
For Cupertino apps, wrap the indicator in a Theme widget or use
CupertinoThemeData extensions.
đ API reference
đ§Š IosBatteryIndicator
| Property | Type | Default | Description |
|---|---|---|---|
height |
double? |
null |
Preferred height. Mutually exclusive with width. |
width |
double? |
null |
Preferred width. Mutually exclusive with height. |
batteryLevel |
int? |
null |
Battery level 0â100. When null, read from the system. |
batteryLevelPollInterval |
Duration |
30s |
Interval between battery-level polls in system mode. |
batteryState |
BatteryState? |
null |
Charging / discharging / full. When null, read from the system. |
showBatteryPercentage |
bool |
true |
Show the percentage number inside the indicator. |
fontFeatures |
List<FontFeature>? |
[.tabularFigures()] |
Font features for the percentage text. Only effective when showBatteryPercentage is true. When the level is exactly 100, any tabularFigures entry is removed (other features are preserved). |
isInBatterySaveMode |
bool? |
null |
Low-power mode. When null, read from the system. |
monitorBatterySaveMode |
bool |
false |
Poll system Low Power Mode when isInBatterySaveMode is null. Supported on Android, iOS, macOS and Windows only (no effect on web or other platforms). |
saveModePollInterval |
Duration |
30s |
Interval between save-mode polls when monitorBatterySaveMode is true. |
lowBatteryThreshold |
int |
20 |
Low Battery Threshold (10â30) below which the indicator turns red. |
chargingWithBolt |
bool |
true |
Show a bolt icon when charging. Only effective when batteryState is .charging. |
playChargingSound |
bool |
false |
Play iOS charging sound in manual mode (iOS only). |
isIOS27Style |
bool? |
null |
Force iOS 27 style. When null, auto-detect the iOS version. |
brightness |
Brightness? |
null |
Force light or dark colors. When null, use ambient brightness. |
animationDuration |
Duration |
Duration(milliseconds: 250) |
Duration for battery indicator animations (fill, colors, bolt). |
themeAnimationDuration |
Duration |
kThemeAnimationDuration |
Animation duration for theme transitions. |
onBatteryLevelChanged |
ValueChanged<int>? |
null |
Called when system battery level changes (system mode only). |
onBatteryStateChanged |
ValueChanged<BatteryState>? |
null |
Called when system battery state changes (system mode only). |
đ¨ BatteryIndicatorTheme
| Property | Type | Description |
|---|---|---|
bgColor |
Color |
Background / border color of the battery shell. |
dischargingTrackColor |
Color |
Fill color when discharging (normal state). |
chargingTrackColor |
Color |
Fill color when charging. Defaults to CupertinoColors.activeGreen. |
criticallyLowTrackColor |
Color |
Fill color when critically low. Defaults to CupertinoColors.destructiveRed. |
saveModeTrackColor |
Color |
Fill color when in battery save mode. Defaults to CupertinoColors.systemYellow. |
contentColor |
Color |
Color used for the bolt icon and cutout text outline. |
contentAntiColor |
Color |
Color used for the percentage text in plain-style mode. |
Factory constructors BatteryIndicatorTheme.light() and
BatteryIndicatorTheme.dark() provide sensible defaults.
See the full API reference: BatteryIndicatorTheme class.
đī¸ Visual states
| Condition | Appearance |
|---|---|
| Normal discharging | Shell border + solid fill proportional to level. |
| Charging | Green fill + bolt icon (if chargingWithBolt is true). |
| Full (100%) | Green fill + no bolt. |
| Low battery (⤠threshold) | Red fill, solid (no cutout). |
| Battery save mode | Yellow fill. |
âšī¸ Additional information
- Repository: github.com/runoob-coder/ios_battery_indicator
- Issue tracker: github.com/runoob-coder/ios_battery_indicator/issues
- Example app: See the
example/directory for a full interactive demo that lets you tweak every property in real time. - Contributions: Pull requests and issues are welcome!
đ Support
If ios_battery_indicator helps you build better UIs, please consider supporting it.
It only takes a few seconds and helps other Flutter developers discover the library.
- â Star on GitHub
- đ Like on pub.dev
âī¸ Buy Me a Coffee



