diff --git a/CHANGELOG.md b/CHANGELOG.md index d6db338..9d453e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 240197e..b57689f 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/lib/src/screen_off.dart b/lib/src/screen_off.dart index b14a742..4a83ff1 100644 --- a/lib/src/screen_off.dart +++ b/lib/src/screen_off.dart @@ -9,12 +9,28 @@ class ScreenOff { static final ScreenOffPlatformInterface _platform = ScreenOffMethodChannel(); /// Turns the device screen off using the platform-specific implementation. - static Future turnScreenOff() async { - await _platform.turnScreenOff(); + /// + /// Returns `true` if the operation was successful, `false` otherwise. + /// May throw a [PlatformException] if the operation fails. + static Future turnScreenOff() async { + try { + await _platform.turnScreenOff(); + return true; + } catch (e) { + return false; + } } /// Turns the device screen on using the platform-specific implementation. - static Future turnScreenOn() async { - await _platform.turnScreenOn(); + /// + /// Returns `true` if the operation was successful, `false` otherwise. + /// May throw a [PlatformException] if the operation fails. + static Future turnScreenOn() async { + try { + await _platform.turnScreenOn(); + return true; + } catch (e) { + return false; + } } }