How to keep application awake in flutter?

前端 未结 2 623
半阙折子戏
半阙折子戏 2020-12-09 07:58

How to keep an application from locking the screen in flutter?

Is there a flag to turn it off an on? Does flutter SDK expose this?

Something like keepA

相关标签:
2条回答
  • 2020-12-09 08:18

    As support for the screen plugin that @Tree mentioned has been discontinued and there are some issues with it now, you can use wakelock.
    Full disclosure: I am the author of this plugin, however, it is basically a port of the wakelock functionality from the screen plugin, with the issues fixed:

    import 'package:wakelock/wakelock.dart';
    
    // To keep the screen on:
    Wakelock.enable(); // or Wakelock.toggle(on: true);
    
    // To let the screen turn off again:
    Wakelock.disable(); // or Wakelock.toggle(on: false);
    

    Learn more.

    0 讨论(0)
  • 2020-12-09 08:20

    I found plugin that does the job. https://pub.dartlang.org/packages/screen

    import 'package:screen/screen.dart';
    
    // Prevent screen from going into sleep mode:
    Screen.keepOn(true);
    

    You also need to set permission for android

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    
    0 讨论(0)
提交回复
热议问题