Dart analyzer is not parsing the dynamic generated files - dart

I checked and the file is OK.
Dart 1.23.0
AngularDart 3.1.0
The error I am getting is:
Target of URI hasn't been generated: 'file.g.dart'

It may help to run "Synchronize" -- bound by default to Ctrl-Q.
You can restart the analyzer on the dart analysis tab, in the top left is a button with arrows running in a circle, if you hover over it it says 'Restart Dart Analysis Server'.
Example picture

first check this article :
https://flutter.dev/docs/development/data-and-backend/json
and make sure of all steps :
1- add dependencies in pubspec.yaml
2- flutter pub get
3- flutter pub upgrade
4- flutter pub run build_runner build
after all, consider that:
part 'timeline.g.dart';
most be your file name which classes are in!
if your file name is difference with your class name, you should use your file name.

Had the same problem. Fixed it following these steps:
$ flutter pub get
$ flutter pub upgrade
$ flutter pub run build_runner build --delete-conflicting-outputs

Check have you created a constructor for class with no default parameters. Basically automated file is generated but error happens because it can not find a contractor for model

flutter pub run build_runner build
Just run the above command in the console. Everything will be fine

Related

Testing solution from Exercism

I just installed Exercism and would like to test if I managed to complete the hello-world assignment.
I changed the hello_world.dart file in the lib folder to print the solution, but now I am struggling with running the test file.
In the guide it says to simply run
$ pub run test
Is the $-sign meant to mean something to me? Cause all I am getting is: "'$' is not recognized as an internal or external command,operable program or batch file." I have the same issue with running "pub get" or "pub run test". (What does pub mean?)
To summarize, I ran:
exercism configure "my token"
exercism download --exercise=hello-world --track=dart
cd C:\Users\Martin\exercism\dart\hello-world
I changed the file in C:\Users\Martin\Exercism\dart\hello-world\lib
And then I tried
$ pub run test
pub run test
pub get
And none of these seem to do anything. So, I don't know how to test my file.
I do have flutter installed and run is fine with Android Studio, if that is relevant. It seems to me that I can choose to write the solution in both notepad++ or Android Studio.
Thanks for any help
pub is package manager for dart programming language, just like npm for javascript. Since you've installed it on WINDOWS i'm guessing you used choco - package manager to install the dart-sdk. https://dart.dev/get-dart.
Once installed make sure you've set dart-sdk the path in Environment variable.

How to run Pub.build() in Dart 2

In Dart 1.x, there was a command, that you could trigger e.g. from grinder.dart. But this line works no longer:
Pub.build();
How can I replace it and run build command of my web app from Dart code?
pub build is no longer supported in Dart 2.
You need to run pub run build_runner build.
See https://webdev.dartlang.org/dart-2
I'm not sure if there are new APIs for Grinder, though.
I fixed it by calling webdev build directly

NPM 'prestart' script equivalent in Flutter

In a package.json file (which is basically the Node version of Flutters pubspec.yaml) You have a scripts section where you can add your own custom scripts. Normally with a node project you'll have a start script that will kick off the build and, well, start the project. In flutter you have flutter run.
In my flutter project I'm using the json_serializable package that generates the code that I use when serialising my objects to JSON. Right now I have to have two terminal windows open:
Tab 1
Runs flutter packages pub run build_runner watch that does the code generation and watches the file system.
Tab 2
Run flutter run that runs the project with hot reloading.
So it would be great if you had something like Nodes prestart in pubspec.yaml where I can run the code generation automatically when I run flutter run
There currently is no such thing in Dart. You can create your own Dart or shell scripts in tool/ that runs your builder_runner command detached (in the background) and the flutter run command in the foreground.
you can start this just using tool/run.dart
However with build becoming mature and pub serve/pub build being deprecated I assume the Dart team is thinking already about making this a more pleasant experience.

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?

Failed to load package in Dart

When I try to import a package with the syntax import 'package:markdown/markdown.dart';, I get no error in Dart Editor but when I run the dart application, the debugger shows me the message:
An error occurred loading file: package:markdown/markdown.dart
Failed to load resource
chrome-extension://gfjabgeipkcfopofkhjimepepnomcidk/dart/packages/markdown/markdown.dart
But when I write the whole path (import "../../packages/markdown/markdown.dart";) everything works fine. I cannot understand why the syntax package: doesn't work in my code though it works in Dart Editor's own examples.
You can see the Chrome app architecture below (I'm loading a package from translator.dart):
You should have the package added as a dependency in pubspec.yaml (which I assume you do).
Also try running following:
delete packages folder
delete pubspec.lock
run pub get to fetch the
dependencies again.
I think in your md_to_html folder you need a link to the 'packages' directory for the shortform to work. I seem to remember this happening when the workspace is built but I'm not sure now which command triggers it, have a look at the current pub docs.

Resources