Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart - How does one dart project import code from another dart project without using pub?

Suppose I have two dart projects

Project A contains code that uses web component to create bunch of UI widget (similar to https://github.com/kevmoo/widget.dart)

Project B contains my front end code that would reuse the UI widget I created in project A.

If I dont want to publish my project A to pub, is there anyway to link project B to project A without manually copying files from project A into B?

Thanks

like image 771
nobody Avatar asked Apr 02 '13 20:04

nobody


People also ask

How do you use darts import?

When importing a library file from another package, use the the package: directive to specify the URI of that file. import 'package:utilities/utilities. dart'; When importing a library file from your own package, use a relative path when both files are inside of lib, or when both files are outside of lib.

How do I import a local file into Flutter?

import 'Package name'; Or using the complete path of the file name. import 'package:path/package name'; This is the process of importing Local packages into flutter in different scenarios.


1 Answers

Take a look at this section in the pub documentation: Path Dependencies:

http://pub.dartlang.org/doc/dependencies.html#path-packages

Suppose project_a had a library file called myprojecta.dart

dependencies:
  project_a:
    path: /Users/me/project_a   <-- root of project a

In your code, you would import project_a using

import 'package:project_a/myprojecta.dart'

Note - if you don't want to publish your project to pub, you can always use git as a dependency rather than path dependency - this lets other people in your team use your projects without relying upon your filesystem layout.

like image 98
Chris Buckett Avatar answered Oct 10 '22 04:10

Chris Buckett