ios_battery_indicator 1.0.2
ios_battery_indicator: ^1.0.2 copied to clipboard
A Flutter widget that replicates the native iOS battery indicator, including support for iOS 27 style and automatic system battery monitoring.
đ 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 | 䏿
| [iOS Battery Indicator] | [iOS Battery Indicator] | [iOS Battery Indicator] | [iOS Battery Indicator] |
|---|
⨠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.
- 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 â
AnimatedSwitchertransitions between basic and percentage display, andAnimatedThemefor theme changes.
đ 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
);
đ¨ Styling #
IosBatteryIndicator(
isIOS27Style: true, // force iOS 27 borderless style
brightness: Brightness.dark, // force dark mode colors
lowBatteryThreshold: 15, // turn red when ⤠15%
);
đ 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
đī¸ 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. |
isInBatterySaveMode |
bool? |
null |
Low-power mode. When null, read from the system. |
showBatteryPercentage |
bool |
true |
Show the percentage number inside the indicator. |
chargingWithBolt |
bool |
true |
Show a bolt icon when charging. |
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. |
themeAnimationDuration |
Duration |
kThemeAnimationDuration |
Animation duration for theme transitions. |
lowBatteryThreshold |
int |
20 |
Low Battery Threshold (10â30) below which the indicator turns red. |
đ¨ 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