battery_flutter 0.0.1 copy "battery_flutter: ^0.0.1" to clipboard
battery_flutter: ^0.0.1 copied to clipboard

A plugin get device battery

battery_flutter #

A Flutter plugin to retrieve the current battery level of the device on both Android and iOS.


๐Ÿ”‹ Features #

  • Get battery level as a percentage
  • Supports both Android and iOS
  • Simple API using MethodChannel

๐Ÿš€ Getting Started #

1. Add dependency #

In your pubspec.yaml:

dependencies:
  battery_flutter: ^0.0.1

Then run:

flutter pub get

2. Import the plugin #

import 'package:battery_flutter/battery_flutter.dart';

3. Usage Example #

final battery = BatteryFlutter();
int? batteryLevel = await battery.getBattery();
print('Battery level: $batteryLevel%');

๐Ÿ“ฑ Example App #

A complete example is available in the example/ directory.

Run:

cd example
flutter run

๐Ÿงช Example UI Widget #

import 'package:flutter/material.dart';
import 'package:battery_flutter/battery_flutter.dart';

class BatteryWidget extends StatefulWidget {
  @override
  _BatteryWidgetState createState() => _BatteryWidgetState();
}

class _BatteryWidgetState extends State<BatteryWidget> {
  int? _batteryLevel;

  @override
  void initState() {
    super.initState();
    _loadBatteryLevel();
  }

  Future<void> _loadBatteryLevel() async {
    final battery = BatteryFlutter();
    final level = await battery.getBattery();
    setState(() {
      _batteryLevel = level;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text('Battery Level: ${_batteryLevel ?? "Unknown"}%'),
    );
  }
}

๐Ÿ“ฆ Platform Support #

Platform Supported
Android โœ… Yes
iOS โœ… Yes
Web โŒ No
Windows โŒ No
macOS โŒ No
Linux โŒ No

๐Ÿ“„ License #

This project is licensed under the MIT License.

0
likes
140
points
107
downloads

Publisher

unverified uploader

Weekly Downloads

A plugin get device battery

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on battery_flutter