wakelock 0.1.1+1 copy "wakelock: ^0.1.1+1" to clipboard
wakelock: ^0.1.1+1 copied to clipboard

outdated

Wakelock is a Flutter plugin that allows you to easily toggle the Android and iOS screen wakelock on or off in order to prevent the screen from automatically turning off. Essentially, this allows you [...]

example/lib/main.dart

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

void main() => runApp(MyApp());

/// The wakelock implementation is located inside the [FlatButton.onPressed] functions and a [FutureBuilder].
/// The [FlatButton]'s and the [FutureBuilder] sit inside the [Column] that is a child of the [Scaffold] in [_MyAppState].
class MyApp extends StatefulWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) => MaterialApp(
          home: Scaffold(
              body: Center(
                  child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
            FlatButton(
              child: const Text('enable wakelock'),
              onPressed: () {
                // The following code will enable the wakelock on Android or iOS using the wakelock plugin.
                setState(() {
                  Wakelock.enable();
                });
              },
            ),
            FlatButton(
              child: const Text('disable wakelock'),
              onPressed: () {
                // The following code will disable the wakelock on Android or iOS using the wakelock plugin.
                setState(() {
                  Wakelock.disable();
                });
              },
            ),
            FutureBuilder(
              future: Wakelock.isEnabled,
              builder: (context, AsyncSnapshot<bool> snapshot) {
                // The use of FutureBuilder is necessary here to await the bool value from isEnabled.
                if (!snapshot.hasData)
                  return Container(); // The Future is retrieved so fast that you will not be able to see any loading indicator.
                return Text(
                    'wakelock is currently ${snapshot.data ? 'enabled' : 'disabled'}');
              },
            )
          ]))));
}
1477
likes
0
pub points
99%
popularity

Publisher

verified publishercreativemaybeno.dev

Wakelock is a Flutter plugin that allows you to easily toggle the Android and iOS screen wakelock on or off in order to prevent the screen from automatically turning off. Essentially, this allows you to keep the device awake, i.e. prevent the phone or tablet from sleeping.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on wakelock