Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba14d67

Browse files
authored
Merge pull request #8 from WilliBobadilla/dev_custom_battery_level
Dev custom battery level
2 parents 2d25e02 + fb6399c commit ba14d67

137 files changed

Lines changed: 3679 additions & 58 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 140 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,160 @@
1-
# flutter_battery_indicator
1+
# flutter_battery_indicator :battery:
22

3-
A battery indicator widget
3+
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.
44

55
![](https://github.com/debuggerx01/battery_indicator/blob/master/example/battery_indicator.gif?raw=true)
66

7+
## Screenshots :camera:
8+
9+
Example with native flutter
10+
11+
<p float="left">
12+
<img src="./example_custom_battery/screenshots/1.jpeg" width="25%" height="35%" />
13+
<img src="./example_custom_battery/screenshots/2.jpeg" width="25%" height="35%" />
14+
</p>
15+
16+
Example with GetX
17+
18+
<p float="left">
19+
<img src="./example_custom_battery_get_x/screenshots/1.jpeg" width="25%" height="35%" />
20+
<img src="./example_custom_battery_get_x/screenshots/2.jpeg" width="25%" height="35%" />
21+
</p>
22+
23+
## Usage :clipboard:
724

8-
## Usage
925
To use this plugin, add `battery_indicator` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).
1026

11-
### Example
27+
```
28+
dependencies:
29+
battery_indicator: ^0.0.5
30+
```
31+
32+
### Examples :iphone:
33+
34+
### You can use your phone battery to display in the widget :one:
1235

13-
``` dart
36+
##### You can check this example in the folder [example]
37+
38+
```dart
1439
// Import package
1540
import 'package:battery_indicator/battery_indicator.dart';
41+
...
1642
17-
// Instantiate it
18-
var batteryIndicator = new BatteryIndicator(
19-
style: BatteryIndicatorStyle.values[_styleIndex],
20-
colorful: _colorful,
21-
showPercentNum: _showPercentNum,
22-
mainColor: _color,
23-
size: _size,
24-
ratio: _ratio,
25-
showPercentSlide: _showPercentSlide,
26-
);
43+
// Instantiate it, by default it takes the battery from your phone
44+
BatteryIndicator(
45+
style: BatteryIndicatorStyle.values[_styleIndex],
46+
colorful: _colorful,
47+
showPercentNum: _showPercentNum,
48+
mainColor: _color,
49+
size: _size,
50+
ratio: _ratio,
51+
showPercentSlide: _showPercentSlide,
52+
);
2753
2854
// and then add it to your layout .
2955
3056
```
3157

58+
### Also you can provide your own battery value :two:
59+
60+
##### You can check this example in the folder [example_custom_battery]
61+
62+
```dart
63+
// Import package
64+
import 'package:battery_indicator/battery_indicator.dart';
65+
...
66+
67+
//inside your statefull class, you can add functions
68+
// to control the battery level, like this:
69+
70+
int bat = 34;
71+
72+
void increment() {
73+
setState(() {
74+
if (bat < 100) {
75+
bat++;
76+
}
77+
});
78+
}
79+
80+
void decrement() {
81+
setState(() {
82+
if (bat > 0) {
83+
bat--;
84+
}
85+
});
86+
}
87+
...
88+
// Instantiate it, add the flag batteryFromPhone, and a
89+
// value to control the battery level
90+
BatteryIndicator(
91+
batteryFromPhone: false,
92+
batteryLevel: bat,
93+
style: BatteryIndicatorStyle.values[_styleIndex],
94+
colorful: _colorful,
95+
showPercentNum: _showPercentNum,
96+
mainColor: _color,
97+
size: _size,
98+
ratio: _ratio,
99+
showPercentSlide: _showPercentSlide,
100+
);
101+
102+
// and then add it to your layout .
103+
104+
```
105+
106+
### Also you can provide your own battery value with GetX :three:
107+
108+
##### You can check this example in the folder [example_custom_battery_get_x]
109+
110+
home_view.dart
111+
112+
```dart
113+
Obx(() => BatteryIndicator(
114+
batteryFromPhone: false,
115+
batteryLevel: controller.bat.value,
116+
style: controller.myStyle,
117+
colorful: controller.colorful,
118+
showPercentNum: controller.showPercentNum,
119+
mainColor: controller.color,
120+
size: controller.size,
121+
ratio: controller.ratio,
122+
showPercentSlide: controller.showPercentSlide)
123+
)
124+
```
125+
126+
home_controller.dart
127+
128+
```dart
129+
class HomeController extends GetxController {
130+
//0,flat and 1,skeumorphism
131+
BatteryIndicatorStyle myStyle = BatteryIndicatorStyle.values[0];
132+
133+
var colorful = true;
134+
var showPercentSlide = true;
135+
var showPercentNum = true;
136+
var size = 35.0;
137+
var ratio = 6.0;
138+
Color color = Colors.blue;
139+
RxInt bat = RxInt(35);
140+
141+
142+
@override
143+
void onClose() {}
144+
void increment() {
145+
if (bat.value < 100) {
146+
bat.value++;
147+
}
148+
}
149+
void decrement() {
150+
if (bat.value > 0) {
151+
bat.value--;
152+
}
153+
}
154+
}
155+
```
32156

33-
## Getting Started
157+
## Getting Started :rocket:
34158

35159
For help getting started with Flutter, view our online [documentation](https://flutter.io/).
36160

example/.flutter-plugins-dependencies

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/ios/Flutter/flutter_export_environment.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/sh
22
# This is a generated file; do not edit or check into version control.
3-
export "FLUTTER_ROOT=/home/debuggerx/flutter"
4-
export "FLUTTER_APPLICATION_PATH=/home/debuggerx/AndroidStudioProjects/battery_indicator/example"
3+
export "FLUTTER_ROOT=/home/usuario/snap/flutter/common/flutter"
4+
export "FLUTTER_APPLICATION_PATH=/home/usuario/Documentos/proyectos/proyectosFlutter/battery_indicator/example"
55
export "FLUTTER_TARGET=lib/main.dart"
66
export "FLUTTER_BUILD_DIR=build"
77
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
88
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
9-
export "FLUTTER_FRAMEWORK_DIR=/home/debuggerx/flutter/bin/cache/artifacts/engine/ios"
9+
export "FLUTTER_FRAMEWORK_DIR=/home/usuario/snap/flutter/common/flutter/bin/cache/artifacts/engine/ios"
1010
export "FLUTTER_BUILD_NAME=1.0.0"
1111
export "FLUTTER_BUILD_NUMBER=1"
1212
export "DART_OBFUSCATION=false"

example_custom_battery/.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
**/ios/Flutter/.last_build_id
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
34+
# Web related
35+
lib/generated_plugin_registrant.dart
36+
37+
# Symbolication related
38+
app.*.symbols
39+
40+
# Obfuscation related
41+
app.*.map.json

example_custom_battery/.metadata

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 8874f21e79d7ec66d0457c7ab338348e31b17f1d
8+
channel: stable
9+
10+
project_type: app

example_custom_battery/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# battery_indicator with flutter
2+
3+
A example of batterry indicator for Andriod and iOS witten in flutter.
4+
5+
## Screnshoots
6+
7+
<p float="left">
8+
<img src="./screenshots/1.jpeg" width="25%" height="35%" />
9+
<img src="./screenshots/2.jpeg" width="25%" height="35%" />
10+
11+
</p>
12+
13+
## Notes
14+
15+
Using the _bat_ variable you can control the value of this variable.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
key.properties
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
def localProperties = new Properties()
2+
def localPropertiesFile = rootProject.file('local.properties')
3+
if (localPropertiesFile.exists()) {
4+
localPropertiesFile.withReader('UTF-8') { reader ->
5+
localProperties.load(reader)
6+
}
7+
}
8+
9+
def flutterRoot = localProperties.getProperty('flutter.sdk')
10+
if (flutterRoot == null) {
11+
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12+
}
13+
14+
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15+
if (flutterVersionCode == null) {
16+
flutterVersionCode = '1'
17+
}
18+
19+
def flutterVersionName = localProperties.getProperty('flutter.versionName')
20+
if (flutterVersionName == null) {
21+
flutterVersionName = '1.0'
22+
}
23+
24+
apply plugin: 'com.android.application'
25+
apply plugin: 'kotlin-android'
26+
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27+
28+
android {
29+
compileSdkVersion 29
30+
31+
sourceSets {
32+
main.java.srcDirs += 'src/main/kotlin'
33+
}
34+
35+
lintOptions {
36+
disable 'InvalidPackage'
37+
}
38+
39+
defaultConfig {
40+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
41+
applicationId "com.example.example_custom_battery"
42+
minSdkVersion 16
43+
targetSdkVersion 29
44+
versionCode flutterVersionCode.toInteger()
45+
versionName flutterVersionName
46+
}
47+
48+
buildTypes {
49+
release {
50+
// TODO: Add your own signing config for the release build.
51+
// Signing with the debug keys for now, so `flutter run --release` works.
52+
signingConfig signingConfigs.debug
53+
}
54+
}
55+
}
56+
57+
flutter {
58+
source '../..'
59+
}
60+
61+
dependencies {
62+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
63+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.example.example_custom_battery">
3+
<!-- Flutter needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.example.example_custom_battery">
3+
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
4+
calls FlutterMain.startInitialization(this); in its onCreate method.
5+
In most cases you can leave this as-is, but you if you want to provide
6+
additional functionality it is fine to subclass or reimplement
7+
FlutterApplication and put your custom class here. -->
8+
<application
9+
android:name="io.flutter.app.FlutterApplication"
10+
android:label="example_custom_battery"
11+
android:icon="@mipmap/ic_launcher">
12+
<activity
13+
android:name=".MainActivity"
14+
android:launchMode="singleTop"
15+
android:theme="@style/LaunchTheme"
16+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
17+
android:hardwareAccelerated="true"
18+
android:windowSoftInputMode="adjustResize">
19+
<!-- Specifies an Android theme to apply to this Activity as soon as
20+
the Android process has started. This theme is visible to the user
21+
while the Flutter UI initializes. After that, this theme continues
22+
to determine the Window background behind the Flutter UI. -->
23+
<meta-data
24+
android:name="io.flutter.embedding.android.NormalTheme"
25+
android:resource="@style/NormalTheme"
26+
/>
27+
<!-- Displays an Android View that continues showing the launch screen
28+
Drawable until Flutter paints its first frame, then this splash
29+
screen fades out. A splash screen is useful to avoid any visual
30+
gap between the end of Android's launch screen and the painting of
31+
Flutter's first frame. -->
32+
<meta-data
33+
android:name="io.flutter.embedding.android.SplashScreenDrawable"
34+
android:resource="@drawable/launch_background"
35+
/>
36+
<intent-filter>
37+
<action android:name="android.intent.action.MAIN"/>
38+
<category android:name="android.intent.category.LAUNCHER"/>
39+
</intent-filter>
40+
</activity>
41+
<!-- Don't delete the meta-data below.
42+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
43+
<meta-data
44+
android:name="flutterEmbedding"
45+
android:value="2" />
46+
</application>
47+
</manifest>

0 commit comments

Comments
 (0)