Coder Social home page Coder Social logo

debuggerx01 / battery_indicator Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 9.0 693 KB

A battery indicator widget for flutter

License: BSD 2-Clause "Simplified" License

Objective-C 0.41% Dart 91.72% Shell 2.02% Kotlin 1.47% Swift 4.37%
flutter battery indicator dart

battery_indicator's Introduction

flutter_battery_indicator ๐Ÿ”‹

A battery indicator widget, you can use the phone battery value to display, and also you can provide your own value for the battery level.

Screenshots ๐Ÿ“ท

Example with native flutter

Example with GetX

Usage ๐Ÿ“‹

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

dependencies:
  battery_indicator: ^0.1.0

Examples ๐Ÿ“ฑ

You can use your phone battery to display in the widget 1๏ธโƒฃ

You can check this example in the folder [example]
// Import package
import 'package:battery_indicator/battery_indicator.dart';
...

// Instantiate it, by default it takes the battery from your phone
BatteryIndicator(
  style: BatteryIndicatorStyle.values[_styleIndex],
  colorful: _colorful,
  showPercentNum: _showPercentNum,
  mainColor: _color,
  size: _size,
  ratio: _ratio,
  showPercentSlide: _showPercentSlide,
);

// and then add it to your layout .

Also you can provide your own battery value 2๏ธโƒฃ

You can check this example in the folder [example_custom_battery]
// Import package
import 'package:battery_indicator/battery_indicator.dart';
...

//inside your statefull class, you can add functions
// to control the battery level, like this:

int bat = 34;

void increment() {
  setState(() {
    if (bat < 100) {
      bat++;
    }
  });
}

void decrement() {
  setState(() {
    if (bat > 0) {
      bat--;
    }
  });
}
...
// Instantiate it, add the flag batteryFromPhone, and a
// value to control the battery level
BatteryIndicator(
  batteryFromPhone: false,
  batteryLevel: bat,
  style: BatteryIndicatorStyle.values[_styleIndex],
  colorful: _colorful,
  showPercentNum: _showPercentNum,
  mainColor: _color,
  size: _size,
  ratio: _ratio,
  showPercentSlide: _showPercentSlide,
);

// and then add it to your layout .

Also you can provide your own battery value with GetX 3๏ธโƒฃ

You can check this example in the folder [example_custom_battery_get_x]

home_view.dart

 Obx(() => BatteryIndicator(
      batteryFromPhone: false,
      batteryLevel: controller.bat.value,
      style: controller.myStyle,
      colorful: controller.colorful,
      showPercentNum: controller.showPercentNum,
      mainColor: controller.color,
      size: controller.size,
      ratio: controller.ratio,
      showPercentSlide: controller.showPercentSlide)
  )

home_controller.dart

class HomeController extends GetxController {
  //0,flat and 1,skeumorphism
  BatteryIndicatorStyle myStyle = BatteryIndicatorStyle.values[0];

  var colorful = true;
  var showPercentSlide = true;
  var showPercentNum = true;
  var size = 35.0;
  var ratio = 6.0;
  Color color = Colors.blue;
  RxInt bat = RxInt(35);


  @override
  void onClose() {}
  void increment() {
    if (bat.value < 100) {
      bat.value++;
    }
  }
  void decrement() {
    if (bat.value > 0) {
      bat.value--;
    }
  }
}

Special Thanks ๐Ÿ‘

WilliBobadilla

Getting Started ๐Ÿš€

For help getting started with Flutter, view our online documentation.

For help on editing package code, view the documentation.

battery_indicator's People

Contributors

debuggerx01 avatar willibobadilla avatar

Stargazers

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

Watchers

 avatar  avatar

battery_indicator's Issues

Upgrade from battery_plus ^2.0.1 to ^3.0.2

Pleas update the package dependencies.

Because battery_indicator 0.1.1 depends on battery_plus ^2.0.1 and no versions of battery_indicator match >0.1.1 <0.2.0, battery_indicator ^0.1.1 requires battery_plus ^2.0.1.
So, because app depends on both battery_plus ^3.0.2 and battery_indicator ^0.1.1, version solving failed.
pub get failed (1; So, because app depends on both battery_plus ^3.0.2 and battery_indicator ^0.1.1, version solving failed.)

Change only internal color

Is it possibile to set custom color only for the internal color?
I want to keep the border black and change the internal color with a custom rule.

Thank you in advance

build failed with battey plus 3.0.3

Hi,

I can't build due to some dependency issues please see attached logs :


.pub-cache/hosted/pub.dev/battery_plus-3.0.3/android/src/main/kotlin/dev/fluttercommunity/plus/battery/BatteryPlusPlugin.kt: (112, 53): Unresolved reference: lowercase

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':battery_plus: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 2s
Exception: Gradle task assembleDebug failed with exit code 1

waiting for a fix if possible
thank you

Suggested Improvement

When you try make the battery size bigger than 20, the font size (where you do widget.size -2) doesn't work too well. I think allowing to pass in a property to set the font size would be nice. Default it to 90% of the size value.

Charging information

If the battery is charging, is there any way to show the information through the battery indicator? Thanks!

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.