You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter应用运行失败求助:intent-1.4.0插件Kotlin空接收器编译错误

Fixing Flutter Build Error with Intent Plugin 1.4.0

Hey there, let's get this Flutter build error sorted out together! The issue you're facing comes from null safety violations in the intent plugin's Android Kotlin code. Here's a breakdown of what's going wrong and how to fix it:

What's Causing the Error?

Kotlin enforces strict null safety, which means you can't call methods directly on a nullable object like Intent? without using either a safe call (?.) or a non-null assertion (!!.). The 1.4.0 version of the intent plugin doesn't handle this correctly in four lines of its IntentPlugin.kt file, leading to the compile errors you see.

The easiest fix is to use a newer version of the plugin where this null safety issue is likely already resolved:

  • Open your project's pubspec.yaml file
  • Locate the intent dependency line and update it to the latest available version (e.g., intent: ^2.0.0 or higher)
  • Run flutter pub get to fetch the updated plugin
  • Restart your build with flutter run

Solution 2: Manually Patch the Plugin Code

If upgrading isn't an option for you, you can edit the plugin's source code directly:

  1. Navigate to the file path from your error message: D:\src\flutter\.pub-cache\hosted\pub.dartlang.org\intent-1.4.0\android\src\main\kotlin\io\github\itzmeanjan\intent\IntentPlugin.kt
  2. Open the file in a text editor or Android Studio
  3. Modify the four problematic lines to use safe calls (safer) or non-null assertions (only if you're certain intent is never null here):
    • Line 50: Replace intent.setAction(action) with intent?.setAction(action) or intent!!.setAction(action)
    • Line 55: Replace intent.addFlags(flags) with intent?.addFlags(flags) or intent!!.addFlags(flags)
    • Line 56: Replace intent.putExtra(EXTRA_STREAM, uri) with intent?.putExtra(EXTRA_STREAM, uri) or intent!!.putExtra(EXTRA_STREAM, uri)
    • Line 58: Replace intent.putExtra(key, value) with intent?.putExtra(key, value) or intent!!.putExtra(key, value)
  4. Save the file, then run flutter clean followed by flutter pub get to refresh dependencies
  5. Try launching your app again with flutter run

Quick Note on Null Safety Syntax

  • ?. is a safe call: it only executes the method if the object isn't null, avoiding crashes
  • !!. is a non-null assertion: it tells Kotlin you guarantee the object isn't null, but will cause a crash if it ever is null at runtime

内容的提问来源于stack exchange,提问作者Syed Saif

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 19:12:49