Problem using my own local dart package

170 views
Skip to first unread message

nat101

unread,
Jul 22, 2019, 5:49:03 PM7/22/19
to Flutter Development (flutter-dev)
I am trying to setup a common local library to be used by multiple projects, and have tried [I think] everything to no avail.

OS: Windows 10
In the common test library project which I have in N:\proj\dart_libs\db2 I have the following pubspec.yaml:

name: db2
description: A starting point for Dart libraries or applications.
version: 1.0.0

environment:
sdk: '>=2.2.0 <3.0.0'

dev_dependencies:
pedantic: ^1.0.0
test: ^1.0.0

 
In another flutter project in: N:\proj\flutter\h001 I have the following inside pubspec.yaml:
environment:
sdk: ">=2.1.0 <3.0.0"

dependencies:
flutter:
sdk: flutter

cupertino_icons: ^0.1.2
http: ^0.12.0+2
mongo_dart: ^0.3.5
date_range_picker: ^1.0.6
time_machine: ^0.9.9
modal_progress_hud: ^0.1.3
db2:
path:/proj/dart_libs/db2: ^1.0.0


dev_dependencies:
flutter_test:
sdk: flutter
-----------------------------------
Note the path beneath db2:  I have tried all kinds of combinations, with the actual dart file, with the drive letter, it always complain on that path, for one reason or other, depending for example, if I include a version constraint or not.

So, what please is the correct way of doing this?

Thank you!

Stuart Morgan

unread,
Jul 22, 2019, 6:52:43 PM7/22/19
to nat101, Flutter Development (flutter-dev)
You can't have a version constraint on a path-based package, since by definition it's using whatever is on disk at that path. The path should be to the root of the package, and thus shouldn't have a Dart file as part of it. See https://dart.dev/tools/pub/dependencies#path-packages.

-Stuart

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/a5a7723b-669d-4461-af9c-b4be1ca0c1f6%40googlegroups.com.

nat101

unread,
Jul 22, 2019, 7:19:46 PM7/22/19
to Flutter Development (flutter-dev)
I did try without a version constraint first (per the docs you referenced) but I got the following error:
            Error on line 20, column 5 of pubspec.yaml: Invalid version constraint: Could not parse version "path:/proj/dart_libs/db2".

So, since it complained about the version, I tried with the constraint. The path is indeed the root of the package. The 'dart_libs' is part of the path to the root of the pkg.
Thanks.
nat
To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.

nat101

unread,
Jul 22, 2019, 10:38:03 PM7/22/19
to Flutter Development (flutter-dev)
I replied in email, thinking that it will post here. Sorry for burdening your inbox with my reply which was as follows:

I got it! (And there is a bug to report.) Currently I have the path line as follows:
path:/proj/dart_libs/db2 
This fails because it  requires one space after the :. If I add a space after the : the 'packages get' works ok and the code is available in the project as expected.
So, that's great. What's the bug? What's the problem? Why was I such an idiot in the first place? It turns out that the EDITOR red flags the line with 'cannot resolve directory', when the syntax correctly has the space. So, at first I indeed had the space, but as soon as it got a red flag, I removed the space, which resulted in the real error.
To summarize, to have the 'get' complete correctly, you need one space, and most importantly, you need to IGNORE THE RED FLAG from the editor.
-nat
Reply all
Reply to author
Forward
0 new messages