battery_info_plugin 0.0.21 copy "battery_info_plugin: ^0.0.21" to clipboard
battery_info_plugin: ^0.0.21 copied to clipboard

PlatformAndroid

A Flutter plugin to get battery information using Android BatteryManager API.

Battery Info Plugin #

Battery Info Plugin is an Android-only plugin that provides comprehensive information from the Android Battery Manager API.

Features #

  • Battery level
  • Charging status
  • Battery health
  • Battery temperature
  • Battery voltage

Installation #

Add battery_info_plugin as a dependency in your pubspec.yaml file:

dependencies:
    battery_info_plugin: latest_version

Usage #

Import the package and use it in your Flutter application:

import 'package:battery_info_plugin/battery_info_plugin.dart';

void getBatteryInfo() async {
    var batteryLevel = await BatteryInfoPlugin.getBatteryLevel();
    var chargingStatus = await BatteryInfoPlugin.getChargingStatus();
}

Example #

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return MaterialApp(
            home: BatteryInfoScreen(),
        );
    }
}

class BatteryInfoScreen extends StatefulWidget {
    @override
    _BatteryInfoScreenState createState() => _BatteryInfoScreenState();
}

class _BatteryInfoScreenState extends State<BatteryInfoScreen> {
    String batteryLevel = 'Unknown';

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

    void getBatteryLevel() async {
        var level = await BatteryInfoPlugin.getBatteryLevel();
        setState(() {
            batteryLevel = '$level%';
        });
    }

    @override
    Widget build(BuildContext context) {
        return Scaffold(
            appBar: AppBar(
                title: Text('Battery Info'),
            ),
            body: Center(
                child: Text('Battery Level: $batteryLevel'),
            ),
        );
    }
}

License #

This project is licensed under the MIT License. See the LICENSE file for details.

Contributions #

Contributions are welcome! Please open an issue or submit a pull request.

Support #

For any questions or issues, please open an issue on the GitHub repository.

3
likes
150
points
70
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to get battery information using Android BatteryManager API.

Homepage

Documentation

API reference

License

GPL-3.0 (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on battery_info_plugin