Unable to run dart command for specific device dart -d - flutter

Flutter and dart is installed successfully. I am able to run a dart file successfully using command line. e.g
//main.dart
void main() {
print('Hello, World!');
}
when i run dart main.dart i can see the output in command line but i am not able to run dart -d command i.e to run a dart test or dart file with specific device or device id.

First of all we need to separate:
The code you showed as example is native Dart without Flutter. So yes your output get only printed in the CommandLine.
If you want a Flutter Project and use the -d argument you first need to set up a Flutter Project using flutter create project_name then you can experiment around and show what you want to the world.
Useful resources which help you to get started:
Write your first Flutter app [flutter.dev Tutorial]
More or less a Flutter Roadmap

Related

How do I run dart code that's isolated from my flutter project without creating a new dart project?

So I'm currently following a tutorial on flutter and it showed this nifty way of running dart code in the same project by creating the new file in the app directory instead of the lib folder. I'm using VS code and can't really figure out how to run the file (they used Android Studio). I tried running the file in the terminal and it kept saying
./scratch.dart: line 1: syntax error near unexpected token `('
./scratch.dart: line 1: `void main() {'
Any idea what I'm doing wrong?
Run dart in terminal to Check that you have dart installed globally with global environment variable in your terminal. If not follow this doc to install https://dart.dev/get-dart.
After making sure that you have dart SDK installed globally in your PC, you can run any dart file containing a void main function in a terminal like
~$ dart path_to_file/scratch.dart
Note: Running un terminal will not work if you are working with a package that utilize dart:ui

Webdev serve : Can't load Kernel binary: Invalid kernel binary format version. No active package webdev

I want to display my mobile application on the web using Flutter. So, I have done the steps to make it.
But,when use webdev serve in command I get an error.
Can't load Kernel binary: Invalid kernel binary format version.
No active package webdev
I attach the photo below:
How I solve this problem? Thank you
Perhaps you have followed rather outdated instructions. webdev is not used anymore.
At the moment, this instruction is relevant.
flutter channel beta
flutter upgrade
flutter config --enable-web
flutter create myapp
cd myapp
flutter run -d chrome
To add web support to an existing project, run the following command in a terminal from the root project directory:
flutter create .

How to do integration testing in Flutter?

I want to do integration testing in Flutter. The tutorial I follow gives the following procedure:
Add the flutter_driver package to pubspec:
dev_dependencies:
flutter_driver:
sdk: flutter
Enable the Flutter driver extension and add a call to
the enableFlutterDriverExtension() function in main.dart.
Run the integration test by using the flutter drive command:
flutter drive --target=my_app/test_driver/my_test.dart
My problem is with understanding step 2. It's not clear to me where in Android Studio do you enable the driver extension and where exactly in main.dart do you call the function enableFlutterDriveExtension().
I also have problems with the third step. After running the said command, it says in my terminal that
Error: The Flutter directory is not a clone of the GitHub project.
The flutter tool requires Git in order to operate properly;
to set up Flutter, run the following command:
git clone -b stable https://github.com/flutter/flutter.git
You have to add this code inside the test_driver/app.dart file.
import 'package:flutter_driver/driver_extension.dart';
import 'package:[YOUR_APP]/main.dart' as app;
void main() {
// This line enables the extension
enableFlutterDriverExtension();
// Call the `main()` function of your app or call `runApp` with any widget you
// are interested in testing.
app.main();
}
You can find more info on the official Flutter documentation site (Steps 3 & 4):
https://flutter.dev/docs/cookbook/testing/integration/introduction
Good luck ;)
In order to run integration test in flutter, you need to create "test_driver" directory inside app root dir. Than you need to create two files inside "test_driver" folder.
Lets call first file "app.dart" and there you need to instrument your app(answer above).
Than you need to create your test file, which needs to be called "app_test.dart" and here you write your actual test code.
When you want to run that test, just run "flutter drive --target=test_driver/app.dart".
About step 3 in your question, check if you set flutter home properly and after adding flutter_driver dependency, run "packages get".

new flutter project in vscode has error

when i create a new flutter project in vscode it will immediately shows an error in the main.dart file and gives a gradle error when trying to debug.
shown here: main.dart error
"compiler message: lib/main.dart:68:19: Error: Too few positional arguments: 1 required, 0 given."
I've reinstalled dart and flutter plugins. updated the java install.
in debug console i get this:
debug console
added output of flutter doctor -v
enter image description here
I was also facing the same error, but it was always on my test folder.
This is what I did:
On your terminal, make sure you are in your project repository.
Run the flutter pub get command, it worked for me, may be you
should try it too.
Do you possibly have two different versions of the Flutter SDK on your machine? I wonder if one is being used by flutter create and the other for analysis.
If you're sure you only have one, please open an issue on GitHub and attach a log file for me to investigate.

Flutter run says '...dependencies could not be established' for the meterial.dart library

I am new to flutter.io and trying to create my first flutter app according to the following guide
https://codelabs.developers.google.com/codelabs/first-flutter-app-pt1/#2
I used terminal command flutter run to start my application and then found an error as follows.
Your application could not be compiled, because its dependencies could not be established.
The following Dart file:
./startup_namer/lib/main.dart
...refers, in an import, to the following library:
/opt/flutter/packages/flutter/lib/meterial.dart
Unfortunately, that library does not appear to exist on your file system.
Couldn't find more details on how to resolve this issue.I am gussing that i should install this library package within my setup.What is the easiest method to install flutter library package from terminal?
Note: i created the app using command flutter create startup_namer
Judging by the error message you have mis-spelled the package in the import statements meterial.dart
It should be:
import 'package:flutter/material.dart';
Note: You may run into same error if you were to change the variable "name: myapp" in your pubspec.yaml file with "import 'package:myapp/settings.dart';" as the custom package in the main.dart file as was intended to add "comanyName" text to the app launcher icons. Fix: changed back to "name: myapp" removed the error