Created
December 12, 2018 05:45
-
-
Save florent37/94b954048ec741e13e72739d9d37b544 to your computer and use it in GitHub Desktop.
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
//From Flutter | |
Future<String> _getBatteryLevel() async { | |
String batteryLevel; | |
try { | |
//invoke the platform specific code | |
//wait for the result | |
final int result = await platform.invokeMethod('getBatteryLevel'); | |
batteryLevel = 'Battery level at $result % .'; | |
} on PlatformException catch (e) { | |
batteryLevel = "Failed to get battery level: '${e.message}'."; | |
} | |
return batteryLevel; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment