Home > other >  Flutter pubspec.yaml: Publishable packages can't have 'path' dependencies
Flutter pubspec.yaml: Publishable packages can't have 'path' dependencies

Time:01-02

I made my own Flutter package 1 year ago and want to update it now. I find an error I didn't see before, so would like to get ideas how to solve it.

Structure
/
∟ pubspec.yaml (pubspec.yaml for my package)
∟ example (example APP that uses my package)
  ∟ pubspec.yaml (pubspec.yaml for this example APP)
  ∟ lib
    ∟ main.dart

Problem
I used to use this below, but now it shows a message: Publishable packages can't have 'path' dependencies. Try adding a 'publish_to: none' entry to mark the package as not for publishing or remove the path dependency.

my_package:
  path: ../

I would like to know how to load my_package (the latest unpublished version) from pubspec.yaml for this example APP while making sure I can publish this package to Pub.dev.

enter image description here

Versions
Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm, locale en-CN)

CodePudding user response:

You can add publish_to: none to the example/pubspec.yaml file since that's the pubspec for the example not the actual package. The package can still be published.

If in doubt look at what other people are doing: this is the flutter_bloc package example/pubspec.yaml

name: example
description: A new Flutter project.
version: 1.0.0 1
publish_to: none

environment:
  sdk: ">=2.13.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_bloc:
    path: ../

dependency_overrides:
  bloc:
    path: ../../bloc
  flutter_bloc:
    path: ../

flutter:
  uses-material-design: true

Notice the publish_to: none.

  • Related