Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.0.7
* Added error handling and success status for screen operations
* Methods now return boolean indicating operation success
* Updated documentation with error handling examples

## 0.0.6
* Update README.md

Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,20 @@ No additional setup is required for iOS. Just make sure the app has permission t
import 'package:screen_off/screen_off.dart';

/// Turn screen off
await ScreenOff.turnScreenOff();
bool success = await ScreenOff.turnScreenOff();
if (success) {
print('Screen turned off successfully');
} else {
print('Failed to turn off screen');
}

/// Turn screen on
await ScreenOff.turnScreenOn();
bool success = await ScreenOff.turnScreenOn();
if (success) {
print('Screen turned on successfully');
} else {
print('Failed to turn on screen');
}
```
### Platform
| Platform | Support |
Expand Down
24 changes: 20 additions & 4 deletions lib/src/screen_off.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,28 @@ class ScreenOff {
static final ScreenOffPlatformInterface _platform = ScreenOffMethodChannel();

/// Turns the device screen off using the platform-specific implementation.
static Future<void> turnScreenOff() async {
await _platform.turnScreenOff();
///
/// Returns `true` if the operation was successful, `false` otherwise.
/// May throw a [PlatformException] if the operation fails.
static Future<bool> turnScreenOff() async {
try {
await _platform.turnScreenOff();
return true;
} catch (e) {
return false;
}
}

/// Turns the device screen on using the platform-specific implementation.
static Future<void> turnScreenOn() async {
await _platform.turnScreenOn();
///
/// Returns `true` if the operation was successful, `false` otherwise.
/// May throw a [PlatformException] if the operation fails.
static Future<bool> turnScreenOn() async {
try {
await _platform.turnScreenOn();
return true;
} catch (e) {
return false;
}
}
}