safeInvokeBool static method
- MethodChannel channel,
- String methodName
safely invokes a method that returns a bool from the native side
channel - represents the native method channel to call
methodName - target method name, make sure no typos exist and that the
native side and the dart side all match !!!
Implementation
static Future<Result<bool, String>> safeInvokeBool(
MethodChannel channel, String methodName) async {
bool? res;
try {
res = await channel.invokeMethod<bool>(methodName);
} on PlatformException catch (e) {
return Result<bool, String>.bad("safeInvokeBool failed: ${e.message}");
}
return res == null
? Result<bool, String>.bad("no result from method invoke.")
: Result<bool, String>.good(res, "Got result.");
}