-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from lichess-org/wakelock
Add wakelock
- Loading branch information
Showing
8 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:wakelock_plus/wakelock_plus.dart'; | ||
|
||
final RouteObserver<PageRoute<void>> wakelockRouteObserver = | ||
RouteObserver<PageRoute<void>>(); | ||
|
||
/// State mixin that enables wakelock when the route is active. | ||
mixin Wakelock<T extends StatefulWidget> on State<T> implements RouteAware { | ||
@override | ||
void didChangeDependencies() { | ||
super.didChangeDependencies(); | ||
final route = ModalRoute.of(context); | ||
if (route != null && route is PageRoute) { | ||
wakelockRouteObserver.subscribe(this, route); | ||
} | ||
} | ||
|
||
@override | ||
void dispose() { | ||
wakelockRouteObserver.unsubscribe(this); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
void didPopNext() { | ||
WakelockPlus.enable(); | ||
} | ||
|
||
@override | ||
void didPush() { | ||
WakelockPlus.enable(); | ||
} | ||
|
||
@override | ||
void didPop() { | ||
WakelockPlus.disable(); | ||
} | ||
|
||
@override | ||
void didPushNext() { | ||
WakelockPlus.disable(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters