battery_level_plugin_abdallah_test 0.0.1 battery_level_plugin_abdallah_test: ^0.0.1 copied to clipboard
Package for getting the battery level.
example/lib/main.dart
import 'package:battery_level_plugin_abdallah_test/battery_level_plugin_abdallah_test.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: BatteryLevelScreen(),
);
}
}
class BatteryLevelScreen extends StatefulWidget {
@override
_BatteryLevelScreenState createState() => _BatteryLevelScreenState();
}
class _BatteryLevelScreenState extends State<BatteryLevelScreen> {
int? _batteryLevel;
Future<void> _getBatteryLevel() async {
final batteryLevel = await BatteryLevelPlugin.getBatteryLevel();
setState(() {
_batteryLevel = batteryLevel;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Battery Level Plugin')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
_batteryLevel != null
? 'Battery Level: $_batteryLevel%'
: 'Press the button to get battery level.',
),
SizedBox(height: 20),
ElevatedButton(
onPressed: _getBatteryLevel,
child: Text('Get Battery Level'),
),
],
),
),
);
}
}