nexus_battery_flutter 0.0.1 copy "nexus_battery_flutter: ^0.0.1" to clipboard
nexus_battery_flutter: ^0.0.1 copied to clipboard

A Flutter plugin to get battery level on Android and iOS using platform channels.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:nexus_battery_flutter/battery_plugin.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _batteryLevel = 'Unknown';

  final _batteryPlugin = BatteryPlugin();

  Future<void> _getBatteryLevel() async {
    final level = await _batteryPlugin.getBatteryLevel();

    setState(() {
      _batteryLevel = level != null ? '$level%' : 'Failed';
    });
  }

  @override
  void initState() {
    super.initState();
    _getBatteryLevel();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Battery Plugin Test')),
        body: Center(
          child: Text(
            'Battery Level: $_batteryLevel',
            style: const TextStyle(fontSize: 24),
          ),
        ),
      ),
    );
  }
}
0
likes
150
points
114
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin to get battery level on Android and iOS using platform channels.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on nexus_battery_flutter

Packages that implement nexus_battery_flutter