Create a local flutter package for myself

Viewed 554

I'm trying to create a local package for my multiple projects.

This is a package with lot of base-designs (think of it as a toolkit)

The problem is that I can't generate my package to add it easily in my projects. I would like to generate it as a "pub" package but without publishing it on the internet and without putting it on a git

So, I opened Visual Studio Code, pressed CTRL+ALT+P, created a new flutter project and selected "packages" names "toolkit_flutter"

I created a "src" folder in "lib" and created a little class with a Text widget. In "toolkit_flutter", I added "export 'src/blabla.dart';" to export my design.

And this is where i'm stuck...

I tried to add a path in "dependencies:" in my pubspect.yaml but I have errors:

The directory 'C:/Users/Naografix/Desktop/toolkit_flutter' doesn't contain a pubspec. Try creating a pubspec in the referenced directory or using a path that has a pubspec.dart(path_pubspec_does_not_exist)

So I changed the path destination to itself and:

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.dart(invalid_dependency)

Then, I added "publish_to: none" and got this error:

[toolkit_flutter] flutter pub get Running "flutter pub get" in toolkit_flutter... Error on line 13, column 3 of pubspec.yaml: A package may not list itself as a dependency.

What can I do?

This is my pubspec.yaml:

name: toolkit_flutter
description: A new Flutter package project.
version: 0.0.1
homepage:
publish_to: none

environment:
  sdk: ">=2.16.1 <3.0.0"
  flutter: ">=1.17.0"

dependencies: 

  toolkit_flutter:
    path: "C:/Toolkit Flutter/toolkit_flutter" 

  flutter:
    sdk: flutter

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^1.0.0

Thank you

1 Answers

As indicated by the "A package may not list itself as a dependency." error message, you gave your private dependency the same name as the package that depends on it (toolkit_flutter). Give them different names. Your private package itself should not need to list any special dependencies in its pubspec.yaml.

In other words:

In your private package:

name: toolkit_flutter
description: My private Flutter toolkit library.
version: 0.0.1
publish_to: none

environment:
  sdk: ">=2.16.1 <3.0.0"
  flutter: ">=1.17.0"

dependencies: 
  flutter:
    sdk: flutter

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^1.0.0

In your application:

name: my_cool_application
description: My cool Flutter application.
version: 0.0.1
publish_to: none

environment:
  sdk: ">=2.16.1 <3.0.0"
  flutter: ">=1.17.0"

dependencies: 
  toolkit_flutter:
    path: "/path/to/toolkit_flutter" 

  flutter:
    sdk: flutter

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^1.0.0
Related