toggle method

Future<void> toggle (
  1. {@required bool on}
)

You can simply use this function to toggle the wakelock using a bool value.

// This line keeps the screen on.
Wakelock.toggle(on: true);

bool turnOnWakelock = false;
// The following line disables the wakelock.
Wakelock.toggle(on: turnOnWakelock);

You can await the Future to wait for the operation to complete.

Implementation

static Future<void> toggle({@required bool on}) {
  assert(on != null,
      'The [on] parameter cannot be null when toggling the wakelock.');
  return _channel.invokeMethod('toggle', {'enable': on});
}