首页 文章

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

提问于
浏览
0

得到这个奇怪的错误 . 似乎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

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

相关问题