ios_battery_indicator 1.2.6 copy "ios_battery_indicator: ^1.2.6" to clipboard
ios_battery_indicator: ^1.2.6 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.

Pub Version License Flutter Demo API Reference GitHub stars

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.
  • System event callbacks — onBatteryLevelChanged and onBatteryStateChanged notify the parent when system values change in auto mode.
  • Manual control — optionally pass batteryLevel, batteryState, and isInBatterySaveMode for 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 the brightness property.
  • 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.onBatteryStateChanged for 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 #

💛 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.

â˜•ī¸ Buy Me a Coffee #

Buy Me a Coffee at ko-fi.com
1
likes
150
points
609
downloads
screenshot

Documentation

API reference

Publisher

verified publishernoob-coder.com

Weekly Downloads

A Flutter widget that replicates the native iOS battery indicator, including support for iOS 27 style and automatic system battery monitoring.

Homepage
Repository (GitHub)
View/report issues

Topics

#battery-indicator #cupertino #widget #ui #components

License

MIT (license)

Dependencies

battery_plus, cutout, device_info_plus, flutter, ios_system_sound, version

More

Packages that depend on ios_battery_indicator