dart-resolve-package-conflicts

作者: flutter

Workflow for fixing package version conflicts. Use this when `pub get` fails due to incompatible package versions.

npx skills add https://github.com/flutter/agent-plugins --skill dart-resolve-package-conflicts

Managing Dart Dependencies

Contents

Core Concepts

Dart enforces a strict single-version rule for dependencies: a project and all its transitive dependencies must resolve to a single, shared version of any given package. This prevents runtime type mismatches but introduces the risk of "version lock."

To mitigate version lock, Dart relies on version constraints rather than pinned versions in the pubspec.yaml. The pubspec.lock file maintains the exact resolved versions for reproducible builds.

Understand the output columns of dart pub outdated:

  • Current: The version currently recorded in pubspec.lock.
  • Upgradable: The latest version allowed by the constraints in pubspec.yaml. dart pub upgrade resolves to this.
  • Resolvable: The absolute latest version that can be resolved when factoring in all other dependencies in the project.
  • Latest: The latest published version of the package (excluding prereleases).

Version Constraints

  • Use Caret Syntax: Always use caret syntax (e.g., ^1.2.3) for dependencies in pubspec.yaml. This allows pub to select newer, non-breaking versions (up to, but not including, the next major version) during resolution.
  • Tighten Dev Dependencies: Set the lower bound of dev_dependencies to the exact version currently used. This reduces resolution complexity and prevents older, incompatible dev tools from being selected.
  • Enforce Lockfiles in CI: Use dart pub get --enforce-lockfile in CI/CD pipelines to ensure the exact versions tested locally are used in production.

Workflow: Auditing Dependencies

Run this workflow periodically to identify stale packages that may impact stability or performance.

Task Progress:

  • Run dart pub outdated.
  • Review the Upgradable column to identify packages that can be updated without modifying pubspec.yaml.
  • Review the Resolvable column to identify packages that require constraint modifications in pubspec.yaml to update.
  • Identify any packages marked as retracted or discontinued.

Workflow: Upgrading Dependencies

Use conditional logic based on the audit results to upgrade dependencies.

Task Progress:

  • If updating to "Upgradable" versions:
    • Run dart pub upgrade.
    • Run dart pub upgrade --tighten to automatically update the lower bounds in pubspec.yaml to match the newly resolved versions.
  • If updating to "Resolvable" versions (Major updates):
    • Manually edit pubspec.yaml to bump the version constraint to match the "Resolvable" column (e.g., change ^0.11.0 to ^0.12.1).
    • Run dart pub upgrade to resolve the new constraints and update pubspec.lock.
  • Feedback Loop:
    • Run dart analyze -> review errors -> fix breaking API changes.
    • Run dart test -> review failures -> fix regressions.

Workflow: Resolving Version Conflicts

When pub cannot find a set of concrete versions that satisfy all constraints, or when dealing with a retracted package version, manipulate the lockfile surgically.

NEVER delete the entire pubspec.lock file and run dart pub get. This causes uncontrolled upgrades across the entire dependency graph.

Task Progress:

  • Open pubspec.lock.
  • Locate the specific YAML block for the conflicting or retracted package.
  • Delete ONLY that package's entry from the lockfile.
  • Run dart pub get to fetch the newest compatible, non-retracted version for that specific package.
  • Feedback Loop:
    • Run dart pub deps -> verify the dependency graph resolves correctly.
    • If resolution fails, identify the transitive dependency causing the lock, update its constraint in pubspec.yaml, and retry.

Examples

Tightening Constraints

When dart pub outdated shows a package is resolvable to a higher minor/patch version, use the --tighten flag to update the pubspec.yaml automatically.

Input (pubspec.yaml):

dependencies:
  http: ^0.13.0

Command:

dart pub upgrade --tighten http

Output (pubspec.yaml):

dependencies:
  http: ^0.13.5

Surgical Lockfile Removal

If package_a is retracted or locked in a conflict, remove only its block from pubspec.lock.

Before (pubspec.lock):

packages:
  package_a:
    dependency: "direct main"
    description:
      name: package_a
      url: "https://pub.dev"
    source: hosted
    version: "1.0.0" # Retracted version
  package_b:
    dependency: "direct main"
    # ...

Action: Delete the package_a block entirely. Leave package_b untouched. Run dart pub get.

来自 flutter 的更多技能

dart-modern-features
flutter
为了找到现代化的候选方案:
flutter-fix-layout-issues
flutter
使用Dart和Flutter MCP工具修复Flutter布局错误(溢出、无界约束)。适用于处理“RenderFlex溢出”、“垂直…
adding-release-notes
flutter
在 DevTools 发布说明中添加面向用户的变更描述。用于在 NEXT_RELEASE_NOTES.md 文件中记录改进、修复或新功能。
reviewing-devtools-prs
flutter
DevTools 仓库专属的PR审查工作流程,执行DevTools风格指南和常见审查模式。在审查……中的拉取请求时使用。
dart-use-primary-constructors
flutter
帮助用户在Dart中编写语法和语义正确的主构造函数,并迁移/使用新的构造函数语法、空体分号语法等。
code-documentation
flutter
编写有效代码文档的指南,包括docstrings、JSDoc、dartdoc和实现注释。在编写新代码、添加…时使用此技能。
api-review
flutter
对照规范的API设计指南审查指定代码。当用户要求进行API审查或根据API设计规范检查代码时,请使用此技能…
flutter-accessibility
flutter
在Flutter应用中实现WCAG 2和EN 301 549无障碍标准及自适应布局。在移动端、网页端和桌面端强制实施语义标注、点击目标尺寸(最小48x48 dp)和文本对比度(小文本4.5:1,大文本3:1)。提供网页语义初始化、交互式组件包裹、基于屏幕尺寸的布局切换以及键盘/鼠标输入处理的决策逻辑。包含通过FocusTraversalGroup实现的焦点遍历管理,以及...