'_Smi'不是'bool'类型的子类型 - Flutter MethodChannel

时间:2018-06-06 23:24:43

标签: android kotlin dart flutter

得到这个奇怪的错误。好像MethodChannel正在转换为int而不是bool?

06-07 00:16:26.589  3678  4993 E flutter : [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
06-07 00:16:26.589  3678  4993 E flutter : type '_Smi' is not a subtype of type 'bool' where
06-07 00:16:26.589  3678  4993 E flutter :   _Smi is from dart:core
06-07 00:16:26.589  3678  4993 E flutter :   bool is from dart:core
06-07 00:16:26.589  3678  4993 E flutter :
06-07 00:16:26.589  3678  4993 E flutter : #0  ...

相关代码:

//the line in question
bool permission = await platform.invokeMethod("askStoragePermission"); 

//the following is the native kotlin that is called.
//The device previously had received permission so it should be going to 
//the 'else' section (and no permission request dialogue appeared)
"askStoragePermission" -> {
  if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this, arrayOf(android.Manifest.permission.READ_EXTERNAL_STORAGE), 35)
    currentResult = result
  } else {
    result.success(true)
  }
}

不知道是什么导致了这一点。它似乎在模拟器中以调试模式工作(此错误是在真实设备上发布apk)。

1 个答案:

答案 0 :(得分:1)

正在运行flutter clean似乎解决了这个问题。确保在每次发布版本之前都这样做,我猜!