Coder Social home page Coder Social logo

battery_info's Introduction

Battery Info

pub package

Flutter plugin, inspired by battery package, providing detailed information about the device battery (level, health, charging status, etc.). Now supports both IOS and Android.

  • Remaining charge time is only available on API level 28 (Android 9 Pie) and higher

๐Ÿ‘€ Unfortunately, due to Apple limitations can only retrieve battery level and charging status for the IOS devices.

Usage

To use this plugin, add battery_info as a dependency in your pubspec.yaml file.

Available battery information

Android :
  • Battery Capacity
  • Battery Level
  • Charging Status
  • Charge Time Remaining
  • Current Average
  • Current Now
  • Health
  • Plugged Status
  • Battery Presence
  • Scale
  • Remaining Energy
  • Technology
  • Temperature
  • Voltage
IOS :
  • Battery Level
  • Charging Status

Example

// Import package
import 'package:battery/battery_info.dart';
import 'package:battery_info/model/android_battery_info.dart';
import 'package:battery_info/enums/charging_status.dart';
import 'package:battery_info/model/iso_battery_info.dart';

// Access current battery health - Android
print("Battery Health: ${(await BatteryInfoPlugin().androidBatteryInfo).health}");

// Access current battery level - IOS
print("Battery Level: ${(await BatteryInfoPlugin().iosBatteryInfo).batteryLevel}");

// Calculate estimated charging time
BatteryInfoPlugin().androidBatteryInfoStream.listen((AndroidBatteryInfo batteryInfo) {
  print("Charge time remaining: ${(batteryInfo.chargeTimeRemaining / 1000 / 60).truncate()} minutes");
});

battery_info's People

Contributors

eliseyozerov avatar igrik12 avatar savy-91 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

battery_info's Issues

Support more platforms

First of all, thank you for this awesome plugin :), the official plugin sucks

As flutter grows, we'd like this plugin to grow with it, so supporting more platforms is essential.

  • macOS support seems very reasonable, since It's not alpha anymore. The implementation may be similar to the iOS implementation. (see this)

โŽ Web is likely out of reach (see this), since the api is deprecated and I couldn't find another one :/

๐Ÿšฅ Windows and Linux are still in alpha stage, so it's is very unlikely that an implementation to these platforms would be good, since the api can change change anytime.

Future<AndroidBatteryInfo?>' can't be assigned to the parameter type 'Future<AndroidBatteryInfo>?'

Hi

I installed the package and created an example same as the package, I got this error.

Running Gradle task 'assembleDebug'...
lib/main.dart:26:47: Error: The argument type 'Future<AndroidBatteryInfo?>' can't be assigned to the parameter type 'Future?' because 'AndroidBatteryInfo?' is nullable and 'AndroidBatteryInfo' isn't.

  • 'Future' is from 'dart:async'.

pubsec.yaml

name: battery_health
description: A new Flutter project.

publish_to: 'none'

version: 1.0.0+1

environment:
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
battery_info:

cupertino_icons: ^1.0.2

dev_dependencies:
flutter_test:
sdk: flutter

flutter_lints: ^1.0.0

flutter:

uses-material-design: true

current now and average incorrect values

the currentNow shows the correct value for some devices but it shows a large incorrect value for some other devices, also the CurrentAverage works for some devices and for others it shows -2147483648

"heath_good" should be "health_good"

In the line 118 of BatteryInfoPlugin.kt, you have:
BatteryManager.BATTERY_HEALTH_GOOD -> "heath_good"

Quite likely "heath_good" should be "health_good" so that the line should look like:
BatteryManager.BATTERY_HEALTH_GOOD -> "health_good"

I am writing a small battery app in flutter and this plugin helps a lot. Happy hacking!

Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Bundle? error

when i tried to run example i'm getting below error

e: C:\Users\G\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\battery_info-1.0.7\android\src\main\kotlin\com\igrik12\battery_info\BatteryInfoPlugin.kt: (66, 36): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Bundle?
e: C:\Users\G\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\battery_info-1.0.7\android\src\main\kotlin\com\igrik12\battery_info\BatteryInfoPlugin.kt: (69, 39): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Bundle?
e: C:\Users\G\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\battery_info-1.0.7\android\src\main\kotlin\com\igrik12\battery_info\BatteryInfoPlugin.kt: (83, 16): Type inference failed. Expected type mismatch: inferred type is Map<String, Any?> but Map<String, Any> was expected

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':battery_info:compileDebugKotlin'.

Compilation error. See log for more details

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 9s

Could you explain better the values in the documentation?

In the documentation of the readme of the package in pub.dev the following is indicated:

Available battery information

Android :
> Battery Capacity
> Battery Level
> Charging Status
> Charge Time Remaining
> Current Average
> Current Now
> Health
> Plugged Status
> Battery Presence
> Scale
> Remaining Energy
> Technology
> Temperature
> Voltage

iOS :
> Battery Level
> Charging Status

But I would like to know what exactly they refer to and in what measures each value is, because it is not well understood.

For example, the Charge Time Remaining, I don't know if it refers to the time it will take to discharge the battery or the time to charge, nor do I know if it is indicated in seconds, milliseconds or in what...
And this happens with more data, for example also with the scale, I don't know what you mean or what data you can give me....

The package is very good, but please explain it better.

Battery info unavailable

I've got following exception on iOS simulator. Is it because of a new Apple policy?

PlatformException (PlatformException(UNAVAILABLE, Battery info unavailable, null, null))

Does it support background service?

I used this package using flutter_background_service. But got error:
W/FlutterJNI( 5246): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: com.igrik12.battery_info/stream. Response ID: 8

iOS battery temperature

Why not use NSProcessInfoThermalState which has 4 states:

  • NSProcessInfoThermalStateNominal
  • NSProcessInfoThermalStateFair
  • NSProcessInfoThermalStateSerious
  • NSProcessInfoThermalStateCritical

Documentation

Not receiving many battery updates when Android device is unplugged

Hello @igrik12 ! Before start, thank you for this package it's very useful.

I'm facing an issue on Android when I disconnect my Android device from the wired to the computer. It receives a lot less battery updates that when is plugged in.

For example, while plugged in, the app receive updates every 200-300 ms, when unplugged it receives updates every 10 seconds...

Can you please help me fix this issue?

Thanks in advance.

Memory leak

Occurs when Flutter Activity is closed
Caught by the LeakCanary tool

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.