battery_level_plugin_abdallah_test 0.0.1 copy "battery_level_plugin_abdallah_test: ^0.0.1" to clipboard
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'),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
140
points
16
downloads

Publisher

unverified uploader

Weekly Downloads

Package for getting the battery level.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on battery_level_plugin_abdallah_test