6

Say my projects' structures are as follows.

    contact_book <---(App)
    ├── bin
    │   └── contact_book.dart
    ├── contact_book.iml
    ├── lib
    │   ├── address.dart
    │   ├── email.dart
    │   ├── field.dart
    │   ├── functions.dart
    │   ├── person.dart
    │   └── phone_number.dart
    ├── pubspec.lock
    └── pubspec.yaml
    functions <---(Package)
    ├── bin
    │   └── lib
    │       └── functions.dart
    ├── functions.iml
    ├── pubspec.lock
    └── pubspec.yaml

Both folders are in the same directory. How do I call a function that's part of a .dart file that's in my other package? From reading the dart website, it seems like it's possible. That way I can write my own functions and use them across different projects. Did I just read that wrong and have to copy the files into my program?

Link: Create Library Packages - Dart

ThinkDigital
  • 3,189
  • 4
  • 26
  • 34

2 Answers2

8

See https://www.dartlang.org/tools/pub/dependencies under "Path Packages". You need only one copy, but you might need to "pub upgrade" whenever you change the included path.

Edit: "You don’t need to run pub every time you change the dependent package." And now I know!

Randal Schwartz
  • 39,428
  • 4
  • 43
  • 70
6

To use the local package "functions", which is located in the same directory as the project "contact_book", add the following code to the file "contact_book/pubspec.yaml":

dependencies:
  functions:
    path: ../functions
syfulin
  • 61
  • 1
  • 1