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

VSCode高亮Flutter项目代码错误,Android Studio无此问题

Fix: Android Studio Not Highlighting Flutter Code Errors

I've run into this exact issue before—VS Code catches Flutter code errors just fine, but Android Studio seems blind to them. Here are the step-by-step fixes that worked for me and other developers:

1. Verify Flutter/Dart Plugins Are Active

First, make sure your IDE has the necessary plugins installed and enabled:

  • Open Settings (File > Settings on Windows/Linux; Android Studio > Settings on Mac)
  • Navigate to the Plugins section
  • Search for "Flutter" and "Dart":
    • If either is disabled, check the box next to it and restart Android Studio
    • If the plugins are outdated, click Update to get the latest versions, then restart

2. Reconfigure Flutter SDK Path

A misconfigured SDK path often breaks code analysis:

  • Go to Settings > Languages & Frameworks > Flutter
  • Double-check that the Flutter SDK path points to your actual Flutter root directory (e.g., ~/flutter or C:\flutter)
  • If it's wrong, click the ... button to select the correct folder, hit Apply, then restart the IDE

3. Force Cache Invalidation & Restart

Android Studio sometimes gets stuck with stale cache data. A full refresh usually fixes this:

  • Click File > Invalidate Caches...
  • In the pop-up, check Invalidate and Restart
  • Wait for the IDE to reboot and reindex your project—this will trigger a full code analysis

4. Enable Dart/Flutter Code Inspections

Make sure Android Studio is set to check for Flutter/Dart errors:

  • Open Settings > Editor > Inspections
  • Expand the Dart category and ensure all critical checks (like Errors, Warnings) are checked
  • Do the same for the Flutter category
  • Click Apply to save changes

5. Refresh Pub Dependencies

Missing or outdated dependencies can throw off code highlighting:

  • Open the terminal at the bottom of Android Studio and run:
    flutter pub get
    
  • After it finishes, click the Sync Project with Gradle Files button (top-right corner) or go to Tools > Flutter > Flutter Pub Get
  • Wait for the sync to complete, then check your code again

6. Confirm Dart SDK is Linked to Flutter

Ensure Android Studio uses the Dart SDK bundled with Flutter (not a standalone one):

  • Go to Settings > Languages & Frameworks > Dart
  • Check Enable Dart support for the project [your-project-name]
  • For Dart SDK path, select the dart-sdk folder inside your Flutter SDK: [flutter-path]/bin/cache/dart-sdk
  • Hit Apply and restart the IDE

If none of these work, try creating a brand new Flutter project in Android Studio. If the new project highlights errors correctly, your original project might have corrupted config files—you can try copying your code into the new project to fix it.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 04:29:25