đ 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.
- 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();
- Battery percentage display is enabled by default.
- Poll the system battery level every 30 seconds.
- 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
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.
đī¸ Custom theme
You can customize the colors by providing a BatteryIndicatorTheme via
ThemeData.extensions:
MaterialApp(
theme: ThemeData(
extensions: [
BatteryIndicatorTheme(
bgColor: Colors.grey.withValues(alpha: .3),
dischargingTrackColor: Colors.blue,
contentColor: Colors.blue,
contentAntiColor: Colors.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. |
batteryState |
BatteryState? |
null |
Charging / discharging / full. When null, read from the system. |
showBatteryPercentage |
bool |
true |
Show the percentage number inside the indicator. |
isInBatterySaveMode |
bool? |
null |
Low-power mode. When null, read from the system. |
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). |
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.
đī¸ 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



