Home > database >  Own common libraries in own dart/flutter projects in VSCode?
Own common libraries in own dart/flutter projects in VSCode?

Time:10-23

I'm working on one project for some time now on flutter. Part of the source code has been designed so that it can be used again as is in other projects.

I'm working with Visual Studio Code.

Now I'm creating a second project. I'd like to organize folders this way:

Parent folder
   Project1 folder
   Project2 folder
   my_library

Is it possible to add the library folder to the projects, as it is not inside their respective folders?

CodePudding user response:

In pubspec.yaml of project 1, refer to the library as:

dependencies:
  my_library:
    path: ../my_library

CodePudding user response:

The way to solve this isn't straightforward for beginners. So I summed up the proposed solutions here (I provide the names out of fairness, and follow related potential discussions below each one).

  1. From Richard Heap:

In pubspec.yaml of project 1, refer to the library as:

dependencies:
  my_library:
    path: ../my_library
  1. From me:

In ../my_library, add a specific pubspec.yaml. Something like:

name: my_libraries
description: my own common libraries

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0 1

environment:
  sdk: ">=2.17.1 <3.0.0"
  
dependencies:
  flutter:
    sdk: flutter
  1. From me:

Drag and drop (maybe there's a menu) your my_libraries folder from a file explorer to the VSCODE Explorer panel, and choose "add folder to workspace". Of course, all dependencies to external libraries used in my_libraries must be specified in its own pub_spec.yaml file.

  • Related