How can I debug Dart Builders with breakpoints in WebStorm - dart

Dart uses the build package to generate code. What if you want to debug your own Builder or an existing one?

Instead of calling pub run build_runner you can execute and debug the file build.dart which can be found here:
.dart_tool/build/entrypoint/
To enter your command like serve as in pub run build_runner serve you can edit your debug configurations:
Put the command inside the field Program arguments:
Click Apply and start debugging again. Webstorm will interrupt when a breakpoint is reached.

Related

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 analyzer is not parsing the dynamic generated files

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

How set release mode in Dart Editor

With the SDK 1.3, when I use pub build in Dart Editor, it generate a lot of files isntead of a one minify file. If I use pub in console with --mode=release, it make only a file.
How I set default mode in Dart Editor?
Somehow, executing pub build through Dart editor will run on debug mode. So far, my work around is to run it though command line.
This is an open issue, although there seems to be no plan regarding this yet.
New
DartEditor now has two distinct menu items for debug and release mode.
Original
I'm not sure what you are asking for. As far as I know --mode=release is default for pub build.
I also don't get only one file with pub build --mode=release.
You can try to add this to your pubspec.yaml:
transformers:
- $dart2js:
minify: true

Dart editor launch configuration

I am a bit confused about the launch is supposed to work. In my project I have a build.dart and a html file.
What I am doing now is run the build.dart and then run the html.
Building the dart and then refresh the browser window works also.
But I see no option to run the build.dart and then automatic refresh dartium?
My favorite method is to click on the index.html in the out directory and hit Command-r (or whatever is equivalent on your OS) to run it. This will run build.dart as well as open Dartium.

Resources