-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add new UI Setting to Keep Screen on
Added the KeepScreenOn lib, alongside the keep screen on UI-Setting on the settings page, which allows a user to keep the screen active if he wishes todo so! fix #432
- Loading branch information
Showing
11 changed files
with
91 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
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,55 @@ | ||
/* | ||
* Copyright (c) 2024. Patrick Schmidt. | ||
* All rights reserved. | ||
*/ | ||
|
||
import 'package:common/service/setting_service.dart'; | ||
import 'package:common/util/logger.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
import 'package:keep_screen_on/keep_screen_on.dart'; | ||
|
||
class KeepScreenOnTrigger extends ConsumerStatefulWidget { | ||
const KeepScreenOnTrigger({super.key, required this.child}); | ||
|
||
final Widget child; | ||
|
||
@override | ||
ConsumerState createState() => _KeepScreenOnTriggerState(); | ||
} | ||
|
||
class _KeepScreenOnTriggerState extends ConsumerState<KeepScreenOnTrigger> { | ||
ProviderSubscription? _providerSubscription; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_providerSubscription = ref.listenManual( | ||
boolSettingProvider(AppSettingKeys.keepScreenOn, false), | ||
(_, val) { | ||
logger.i('Keep screen on: $val'); | ||
if (val) { | ||
logger.i('User requested to keep screen on at all times'); | ||
KeepScreenOn.turnOn(); | ||
} else { | ||
logger.i('User requested to NOT keep screen on at all times'); | ||
KeepScreenOn.turnOn(); | ||
} | ||
}, | ||
fireImmediately: true, | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return widget.child; | ||
} | ||
|
||
@override | ||
void dispose() { | ||
super.dispose(); | ||
_providerSubscription?.close(); | ||
logger.i('Dispose KeepScreenOnTrigger, disabled keep screen on'); | ||
KeepScreenOn.turnOff(); | ||
} | ||
} |
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
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