Reputation: 3539
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
Upvotes: 7
Views: 6148
Reputation: 71
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
Upvotes: 7
Reputation: 44186
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!
Upvotes: 8