power 0.2.0+1 copy "power: ^0.2.0+1" to clipboard
power: ^0.2.0+1 copied to clipboard

outdated

A Flutter plugin to access device power related information.

Power #

A Flutter plugin to access device power related information.

pub package

Usage #

To use this plugin, add power as a dependency in your pubspec.yaml file.

  dependencies:
    flutter:
      sdk: flutter
    power: ^0.2.0+1

Example #

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _lowPowerMode = false;
  num _batteryLevel = -1;

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

  Future<void> initPowerState() async {
    bool lowPowerMode;
    num batteryLevel;

    lowPowerMode = await Power.isLowPowerMode;
    batteryLevel = await Power.batteryLevel;

    if (!mounted) return;

    setState(() {
      _lowPowerMode = lowPowerMode;
      _batteryLevel = batteryLevel;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Power example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Text('Low power mode is ${_lowPowerMode ? 'on' : 'off'}'),
              Text(
                  'Battery level is ${_batteryLevel == -1 ? 'Unavailable' : _batteryLevel}'),
            ],
            mainAxisAlignment: MainAxisAlignment.center,
          ),
        ),
      ),
    );
  }
}

Features #

  • Get low power mode
  • Get battery level
  • Get charging status
  • Build widgets in response to power changes
  • Disable animations in low power mode
7
likes
0
pub points
82%
popularity

Publisher

unverified uploader

A Flutter plugin to access device power related information.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on power