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

For Plug In testing that retrieves the battery of the current device.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:battery_plugin/battery_plugin.dart';
import 'package:battery_plugin/battery_plugin_screen.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 _platformVersion = 'Unknown';
  final _batteryPlugin = BatteryPlugin();

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    try {
      platformVersion =
          await _batteryPlugin.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: BatteryPluginScreen(), // Change this line
    );
  }
}
1
likes
130
points
19
downloads

Publisher

unverified uploader

Weekly Downloads

For Plug In testing that retrieves the battery of the current device.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, logger, plugin_platform_interface, rxdart

More

Packages that depend on battery_plugin

Packages that implement battery_plugin