9

I'm learning Dart, but I found a problem:

I want to add the widget.dart package from its GitHub repository as a dependency for my project. But in pub.dartlang.org there is very old version, which requires the obsolete Web UI. Does anyone know, how to get the pub from GitHub repository (and install it like the one from the pub.dartlang.org)?

I'm using GitHub on Windows and Dart Editor.


Update: I tried to add it into a dependency and run 'pub get' in the classic way:

dependencies:
  widget:
    git: git@github.com:dart-lang/widget.dart.git

But it returns this error:

--- 30.1.2014 15:35:27 Running pub get ... ---
Pub get failed, [1] Resolving dependencies...
Cannot get widget from Git (git@github.com:dart-lang/widget.dart.git).
Please ensure Git is correctly installed.
e:\b\build\slave\dart-editor-win-stable\build\dart\sdk\lib\_internal\pub\lib\src\source\git.dart 42  GitSource.downloadToSystemCache.<fn>
dart:isolate                                                                                         _RawReceivePortImpl._handleMessage

This is an unexpected error. Please run

pub --trace 'get'

and include the results in a bug report on http://dartbug.com/new.

** Warning: Application may fail to run since packages did not get installed.Try running pub get again. **
aleskva
  • 1,644
  • 2
  • 21
  • 40
  • 1
    I don't know why adding the github repository isn't an option anymore. You can clone it to you local drive (or use the download ZIP option) and use `path: ../widget` as dependency. There is not much difference between these two. You could clone it to your local drive and publish it yourself, but I guess the maintainer wouldn't like that much. The last option would be to set up your own pub server and use this as dependency. – Günter Zöchbauer Jan 30 '14 at 14:35
  • can you try if `git clone git@github.com:dart-lang/widget.dart.git` works from your command line, to check if git is properly installed. If you don't have git and don't want to install it, you can download the zip. See my updated answer. – Günter Zöchbauer Jan 30 '14 at 14:42
  • 1
    Yes, it works perfectly as usual - no warnings, no errors, I cloned the git repo to my local space... – aleskva Jan 30 '14 at 14:49
  • pub has installation instructions for every package: http://pub.dartlang.org/packages/widget#installing – Janus Troelsen Jan 31 '14 at 16:24
  • Off topic Janus, but thanks for effort to help – aleskva Feb 01 '14 at 20:40

1 Answers1

13

Add the dependency in pubspec.yaml like

Edit pubspec.yaml in text mode

dependencies:
  widget:
    git: git@github.com:dart-lang/widget.dart.git

Use the assistant

if you open the pubspec.yaml file in DartEditor you get a nice assistant

  1. click Add...
  2. Enter name of package: 'widget'
  3. Change the lookup Source from hosted to git
  4. Set Git ref: to git@github.com:dart-lang/widget.dart.git

Additional Info:

  • You can look up the dependency name in the file pubspec.yaml in the widget's GitHub repository under name: widget
  • You can copy the git path from the GitHub repository under SSH clone URL (above the 'Download ZIP` button)

EDIT
To make this work you need to have the git command line client installed on your local system.

You can download the repository manually

git clone git@github.com:dart-lang/widget.dart.git

and add the following dependency

dependencies:
  widget:
    git: ../widget.dart
    # path: ../widget.dart # would work too

Alternatively you can download the repository from GitHub (Download as ZIP) extract it to your local drive and use a path: dependency like

dependencies:
  widget:
    path: ../widget.dart

provided you extracted the ZIP to a sibling folder of your package.

See also https://www.dartlang.org/tools/pub/dependencies#git-packages

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Well, I'm not beginner. I tried it, but still the same problem when getting pub: _--- 30.1.2014 15:26:25 Auto running pub get ... --- Pub get failed, [1] Resolving dependencies... Cannot get widget from Git (git@github.com:dart-lang/widget.dart.git). Please ensure Git is correctly installed. e:\b\build\slave\dart-editor-win-stable\build\dart\sdk\lib\_internal\pub\lib\src\source\git.dart 42 GitSource.downloadToSystemCache. dart:isolate _RawReceivePortImpl._handleMessage_ – aleskva Jan 30 '14 at 14:28
  • @AlesKvapil I thought I could just do a complete write-up of the topic - for anyone interested. No offence meant. I added the package to a playground package of mine and it was immediately downloaded and added to the package subdirectory. – Günter Zöchbauer Jan 30 '14 at 14:31
  • I think I didn't write my question so clearly, sorry, that's my fault. – aleskva Jan 30 '14 at 14:41
  • Could you describe, how to make it with git cl? – aleskva Jan 30 '14 at 14:44
  • 1
    I tried your suggestion after your last edit and everything works! Thank you... *--- 30.1.2014 15:55:24 Auto running pub get ... --- Resolving dependencies............................................ Got dependencies!* – aleskva Jan 30 '14 at 14:57
  • Do you have any idea why it made the error, when I tried it directly from the Dart Editor? Could it be a bug? – aleskva Jan 30 '14 at 15:09
  • @AlesKvapil have you tried `pub --trace 'get'` and checked if it provides additional information about the failure? – Günter Zöchbauer Jan 30 '14 at 15:11
  • Now I'm really confused: pub get/upgrade/--trace get works correctly in the command line, but not in the editor... – aleskva Jan 30 '14 at 15:28
  • Sorry, I think I can't help with that. – Günter Zöchbauer Jan 30 '14 at 15:31
  • I'll try to fix it somehow, then I'll ask a new question on Stack or fill in the bug. Thanks for you help – aleskva Jan 30 '14 at 15:42