Sonar shows Flutter import errors (package:flutter/material.dart not found)

Hi everyone ,

I’m facing a persistent issue with SonarCloud Flutter analysis where Flutter framework imports are reported as unresolved, even after a full compilation step, as recommended in Sonar documentation.


Problem Description

During SonarCloud analysis, I get errors like:

Target of URI doesn't exist: 'package:flutter/material.dart'

As a result, core Flutter symbols are marked as unresolved:

  • StatefulWidget

  • State

  • BuildContext

  • MaterialApp

However:

  • The project builds successfully

  • flutter analyze passes locally and in CI

  • The issue appears only in SonarCloud


Environment

  • Flutter (stable)

  • SonarCloud

  • CI/CD (Linux-based runner)

  • Flutter project (non-web-only, multi-platform)


What I’m Already Doing (Important)

I’m explicitly following Sonar’s recommendation that Dart analysis requires compilation to generate semantic information
(ref: Sonar community post about Flutter requiring build before analysis).

CI/CD Steps (Simplified)

- flutter --version
- flutter pub get

# Optional code generation
- flutter pub run build_runner build --delete-conflicting-outputs || true

# FULL compilation (multiple fallbacks)
- flutter build web --release --no-pub || \
  flutter build apk --debug --no-pub || \
  dart compile kernel lib/main.dart -o /dev/null

# Verify Dart context
- test -f .dart_tool/package_config.json
- grep '"name": "flutter"' .dart_tool/package_config.json

# Generate analyzer report
- flutter analyze --machine > flutter_analyze_report.json

# SonarCloud scan
- sonarcloud-scan

Verification Checks

  • .dart_tool/package_config.json exists

  • Flutter SDK is listed inside package_config.json

  • Compilation artefacts exist under .dart_tool/

  • Analyser report is successfully generated

Despite all this, Sonar still fails to resolve:

package:flutter/material.dart


Questions

  1. Is flutter build web / apk sufficient for SonarDart semantic analysis, or is a specific build target required?

  2. Does SonarCloud require access to Flutter SDK sources in a specific path or env variable?

  3. Is sonar.dart.analysis.mode=flutter still required, or deprecated?

  4. Is this a known limitation/bug with SonarDart in CI environments?

Hi,

Welcome to the community and thanks for this report!

I’m sorry to answer your questions with a request, but can you share a full, debug analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Thx,
Ann