error: Target of URI doesn't exist: 'package:test/test.dart' - dart

Since the latest flutter update my tests are broken.
It looks like the Dart test framework isn't available anymore:
error: Target of URI doesn't exist: 'package:test/test.dart'.

If you've upgraded to a recent master, you'll find that flutter_test has removed its dependency on package:test. The package hasn't been removed or renamed, but you will need to specifically add it to you dev_dependencies in your pubspec now:
dev_dependencies:
test: ^1.5.1
The test_api package is just used to unify the versioning and reduce the depencies of flutter_test. It didn't replace package:test. There are also no breaking changes in any of these newer test versions.

The problem for me targeted URI doesn't exist was due to lib folder inside test package was not available at
file:///E:/APPS/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/dartz-0.9.2/lib/
so I downloaded it from GitHub and add it there manually and restarted the IDE. And It worked.

Related

Flutter Plugin -- build for iOS works in xCode, but doesn't work with flutter build because of package dependency

I am developing a Flutter plugin, which requires a third party library. This library is hosted on GitHub, and to add it to my project, they tell me to use XCode's package manager (File -> Add Packages). When I do it this way, I can use the package just fine, compile my code and run it on my iPad. However, when I try to use "flutter build ios", it doesn't work.
When building, I see a series of (with actual framework names and file names instead of ...):
note: Removed stale file ...
note: Removed stale file ...
note: Removed stale file ...
Then eventually I will see that the compilation has failed due to being unable to import the library I need. Additionally, when I go back into XCode, I find that the package dependency I had installed is no longer there.
So, what I suspect is happening, is when Flutter builds it is cleaning up all the old frameworks, and running its own pod install. However, since my package is not part of my podspec file, it is being left behind. I am unsure how to get this to work. I've tried adding a line in my podspec file like:
s.dependency 'PackageName'
s.source { :git => 'https://linkToTheGitRepo' }
and then running pod repo update, but when I go to build I still get "Unable to find a specification for PackageName depended upon by my_plugin".
At this point, I just build in XCode and then don't touch it, however this has also caused issues when I go to use the plugin later in another project -- I also cannot use flutter build ios in that project, and I have to do it through XCode. This is an annoying workaround, since I lose the hot reload ability and other nice features of working with Flutter. Any suggestions are appreciated. Thanks.

Angular Dart Import Error With Tracing.dart

I am using Angular Dart for a project. In my pubspec.yaml I have
dependencies:
browser: any
angular: "^1.1.2+2"
shadow_dom: any
json_object: any
bootjack: any
crypto: any
xml: "^2.3.2"
transformers:
- angular
for my dependencies. When I run my program in Dartium I get the error
The requested built-in library is not available on Dartium.'package:angular/tracing.dart': error: line 9 pos 1: library handler failed
import "dart:developer";
^: package:angular/tracing.dart
I never reference or use anything out of the tracing.dart so I'm not sure why this is causing an error.
The tracing package is directly using dart:profiler, which was deprecated and now removed. You can now use dart:developer instead, both libraries are compatible.
I would suggest to fork the package, replace dart:profiler with dart:developer (no other changes are required) and send a pull request. I already forked and fixed the package some time ago here, but I think the original package is inactive so I didn't created an PR. You can use my fork by adding this to your pubspec.yaml:
dependency_overrides:
tracing:
git: https://github.com/Fox32/tracing.dart.git
dart:profiler was recently renamed to dart:developer. One of your dependencies probably use an analyzer version that doesn't fit to your Dart version.
See also https://github.com/dart-lang/pub/issues/1345

Dart: pub get vs pub upgrade

According to the pub get docs the main difference between pub get and pub upgrade is:
If a lockfile already exists, pub get uses the versions of dependencies locked in it if possible. If a dependency isn’t locked, pub will get the latest version of that dependency that satisfies all the version constraints. This is the primary difference between pub get and pub upgrade, which always tries to get the latest versions of all dependencies.
But this leaves me with a few questions.
What do they mean by "If a dependency isn't locked...? Locked?!? Like in version control? File system lock? What is this lock of which they speak?
Still not clearly understanding the difference between these two commands. Are they saying that pub get takes version constraints into account, and that pub upgrade doesn't?
It is locked when the pubspec.lock file contains an entry for this dependency.
You can change the dependency in pubspec.lock manually to specify exactly what version you want to use.
pub upgrade checks for the newest version that fits your pubspec.yaml configuration and updates your pubspec.lock file automatically.
when pubspec.lock is checked in with your package code in a CVS repository you are able to later reproduce the exact same setup as you had when you checked in your code even when your pubspec.yaml allowed a wider range of versions for a dependency.
see also
Upgrading a dependency
In Dart and Pub, should I add pubspec.lock to my .gitignore?

Dart Package Management via dart2js

I'm learning Dart and its dependency manager pub and am having a tough time seeing the "forest through the trees" here.
Say I want to use Polymer.dart in my project. So, in my project root, I create the following pubspec.yaml:
name: test_dart
description: A sample web application
dependencies:
browser: any
polymer: ">=0.9.0 <0.10.0"
I then run pub get, which goes to the pub repo and fetches the browser and polymer dependencies that I've specified. It then creates a packages directory in my project root, which now means I have a project that looks like:
MyDartProject/
pubspec.yaml
myapp.dart
packages/
browser/
...
...all the packages that ship with Polymer
Now I start coding my Dart web app (myapp.dart), which will references various Polymer and browser types/functions/etc. in its source code.
When I'm all done, I want to create a JavaScript file called myapp.js.
According to the dart2js docs, I need to run something like:
dart2js --out=myapp.js --package-root=??? myapp.dart
How do I include all the browser & polymer packages on the buildpath?
There is a "pub build" option now.
http://pub.dartlang.org/doc/pub-build.html
Use pub build when you’re ready to deploy your web app. When you run
pub build, it generates the assets for the current package and all of
its dependencies, putting them into a new directory named build.
$ cd ~/dart/helloworld
$ pub build
Building helloworld......
Built 5 files!
If the build directory already exists, pub build deletes it and then creates it again.
That should do everything you are after here. You can also launch it from the IDE by right clicking on the pubspec.yaml file and choose "pub build"
EDIT: You should also see the links in zoechi's answer.
If you run dart2js from your MyDartProject directory you don't have to provide --package-root parameter.
An alternative way is running pub build. If you use Polymer you need to add a transformers section.
see also
How to deploy a Dart Polymer app to Javascript using dart2js
How do I pass multiple entry_points to polymer transformer in pubspec.yaml?

pubspec.yaml deprecated layout

Here is my pubspec.yaml.
name: oct
version: 0.1.0
description: >
Ojus Chemistry Toolkit (OCT) is an open-source toolkit for solving a
variety of cheminformatics problems. It is developed in Dart, mostly.
dependencies:
args:
sdk: args
When I run pub install, I receive a warning as follows.
Warning: Package "oct" is using a deprecated layout.
Reading pub's package layout details, I have not yet understood what is triggering the above warning. Request help! Thanks!
Most likely, you have some .dart files outside predefined directories:
lib
web
test
New SDK gives a helpful link if this problem occurs: http://www.dartlang.org/docs/pub-package-manager/package-layout.html
Lesiak is mostly right. You'll get this warning if pub finds any .dart files in your package's root directory. In the old layout, that was where you put your publicly importable files.
In the new layout, those should go under lib.

Resources