Dart Input in VSCode - dart

How to get input in dart on vscode?
When I click the "Run" button, it only runs the code on the uneditable-terminal, but when I use the "F5" button to run it, as in Python, it brings an error that I need to do some installation and/or configurations, and it auto-creates a "launch.json" file.

please make sure that your dart sdk is installed correctly and then ensure that you install the dart extension for VS code. That should sort you out.

Use cd to get into the directory, then open the terminal and run dart filename.dart.

Related

How debug Kotlin on iOS with Xcode

Currently I am working on one KMM project. It would be really useful to be able to debug the shared code which is in kotlin in xcode project.
I am aware of this solution but I have problem to tell Xcode that *.kt files are source files
to be more specific in the above github link it is written :
You need to tell Xcode that *.kt files are source files, and run an lldb formatter script when debugging starts. Advanced users may want to do this manually, but if you have Xcode installed in the default place, you can run the setup script.
Unless you're using Xcode 11 (in which case look here for help), the following script will install both debugging and formatting support:
./setup.sh
I do not know where and how I should run the ./setup.sh or if there is another way to do it?
The setup script is included in the github repository: https://github.com/touchlab/xcode-kotlin/blob/main/setup.sh
The above plugin is great if you want to debug on Xcode and I highly recommend it.
Just an FYI, in case you didn't notice, there is also a plugin for debugging shared code on iOS for Android Studio: https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile

Create and Run Dart Console Application Using VSCode?

I can create Flutter new application using VSCode. Now I want to learn Dart programming language.
How can I create and run a Dart console application Using VS Code?
There is an easy way to create and run a Dart console application:
Open VSCode
Press cmd + shift + p on Mac or ctrl + shift + p on windows.
Choose Dart: New project
4.Then you should select Console Application
5.After locating console application everything is ready for you 😊
Well, how to run it? So easy!!!🙂
Just go to terminal and type: "dart main.dart"
or copy the main.dart path then type: "dart (paste main file path)"
or press ctrl + F5
That's it. I hope you enjoy. 😁
To run a Dart console application:
Install the Code Runner Extension
Open the Dart code file in Text Editor, then use shortcut Ctrl+Alt+N, or right click the Text Editor and then click Run Code in context menu, the Dart console application will run and the output will be shown in the Output Window.
Steps to run in VS Code:
Open Visual Studio Code.
Close whatever folder you have open.
Make sure you have Dart Code Extension installed, or install it if you don't have it.
Press Ctrl + Shift + P on Windows or Cmd + Shift + P on Mac
Select Dart: New Project
Select Console Application
Type in a name, example: hello_world
Hit Enter
Select a folder that already exists.
Wait until it finishes
main.dart file will show up.
Hit Ctrl + F5 to run or Run, Run without debugging.
In the Debug Console window, you will see the result.
Dart SDK installing with Flutter.
For MacOS Dart directory /Users/burak/flutter/bin/cache/dart-sdk/bin
Add to PATH this bin directory and use dart with below.
dart --version
Run .dart file.
dart main.dart
I found a way to do it, you can install packages etc as well. instructions below..
- Installing
pub global activate stagehand
- Add to .bash_profile
export PATH="$PATH":"$HOME/.pub-cache/bin"
- Create and download packages
mkdir fancy_project
cd fancy_project
stagehand console-full
pub get
If you are not only flutter mobile developer, but web-developer too, you are probably using npm or yarn. If so you can use nodemon to run your dart code automatically after any change
install brew and npm if you don't have it
install $ npm install -g nodemon (or yarn: $ yarn global add nodemon )
Create dart project.
Create nodemon.json file
{
"watch": [
"lib/" // or any other place where you hold the dart files
],
"execMap": {
"dart": "dart"
},
"ext": "dart"
}
Run you code: $ nodemon ./lib/main.dart
p.s. Code in the .dart file should have main function:
void main() {
print('hello world');
}
If you are using VsCode, just save code by CMD + S and nodemon demon will run updated code,
If you already have flutter (windows) installed , then find where you installed flutter. Once you are in flutter folder then go through
flutter\bin\cache\dart-sdk\bin .
I have installed flutter on C:\src folder so my path is
C:\src\flutter\bin\cache\dart-sdk\bin .
Now copy this full path and set it as environment variable.
If you can't set environment variable then open search bar and type "env" . Click the result click environment variable and add that path in( Path variable).
In VScode Ctrl+Shift+` this will open a new terminal . Right click on your dart code and copy path.
In terminal just type this line without bracket and press enter
[dart "paste path"]
If you have already run flutter application on VSCode, then you should be able to run dart console applications. However, please check the following:
Dart SDK is already installed on your system.
Check if the Dart 2.20 Extension (Current Version) is already installed on the VSCode. If not, please install the same on your VSCode, and restart VSCode.
Create Dart console application and save with .dart extension (say Hello.dart), in a suitable location.
From the top menu bar of VSCode, open a terminal. From the
terminal inside of the VSCode, change to directory where you have saved
the dart program.
Run the dart console program with the command:
dart [hello.dart]
Console program results are shown in the terminal. I hope this is what you are looking for.
You can insert this JSON code in your setting.json in the .vscode folder .
"dart.sdkPath": "[DART_SDK_PATH]"
For example in my Windows OS :
"dart.sdkPath": "F:\\dev\\sdk\\dart-sdk"
And My All Setting in setting.json :
{
"version": "0.2.0",
"configurations": [
{
"name": "Dart",
"program": "bin/main.dart",
"request": "launch",
"type": "dart"
}
] ,
"dart.sdkPath": "F:\\dev\\sdk\\dart-sdk"
}
Notice the This Image :
boom that's it. it will print value in console.
Straight Forward Answer
Install Flutter SDK ( this contains dart SDK by default )
Add dart to you environment path
Now create a dart file and run it with the dart command, for example create sunday.dart file and put the following content inside.
void main(){
print("HAVE A NICE DAY")
}
run the dart code with the following code
dart sunday.dart the output will be
HAVE A NICE DAY
Have a look at the dcli package. It is an sdk for building console apps in dart.
To create a sample dart console app that demonstrates a number of best practices run
dcli create --template=full myproject

Flutter run command error : FlutterView.send called on a detached view

Can anyone tell me why my app is not installing at all and ending with the error message
Observatory connection never became ready.
the app was working perfectly fine until yesterday .
I have changed the channel to master yesterday in the command prompt and from then on the app never runs.
I even switched back to channel alpha but still no use.
I have attached a screenshot of the command prompt where the installation was stuck forever.
I am not so sure if I need to reinstall the flutter. I am worried if I uninstall the flutter now it may not configure properly and I might break it forever.
Please can someone tell me what exactly might have gone wrong.
Many Thanks,
Mahi
Instead of reinstall try with following: (Mac)
Set Path Variable: via following terminal command
export PATH=~/flutter/bin:$PATH;
that is bin folder path of flutter.
export PATH=[PATH_TO_FLUTTER_GIT_FOLDER]/bin:$PATH
https://flutter.io/setup-macos/#update-your-path
If above not worked. Check with the Dart version
dart --version
Install the latest dart version:
brew install dart --devel
Hope this helps others.
For Mac
open terminal
$ echo $PATH
it will show like this
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:
it means you need to add flutter in to path
Open Finder presss command + shift + G
Put /etc/paths in dialog and press GO
Copy the file "paths" and paste it on desktop
Then open the pasted "paths" file from desktop
and add following line into end of the file "/flutter/bin"
Then copy that file and again paste it on /etc/paths
same like step no 2
it will ask you to replace or not
press replace
Now if you hit $ echo $PATH on terminal it will show
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/swagat/development/flutter/bin
Now your $flutter doctor will work perfectly
The solution is from Google Groups #Flutter-Dev
Thank you very much for your reply #Michael Thomsen.
I've tried what you have suggested and the details are as follows:
When I used flutter run -v command the command prompt output is as follows:
It was stuck for a while at waiting for port connection if I am not wrong.
So I've used AndroidStudio, File>Open and selected android/ folder to run the app then the gradle was showing an error:
Error:Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (25.2.0) and test app (25.4.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
I modified the build.gradle(Module:app) to show the correct version of 25.2.0 which was previously showing 25.4.0.
dependencies {
androidTestCompile 'com.android.support:support-annotations:25.2.0'
}
I just saved the changes inside android studio and the gradle sync completed without any errors.
Now I can run the app from inside Android Studio and also from IntelliJ IDE.
Thanks very much Michael this solved my problem.
Reinstalling flutter would be my starting point. If this problem persists, please post the output of $>flutter doctor and a description of what exactly leads to this error.

Deploying Angular Dart component with canvas via shadowRoot: what is missing?

I have an angular dart application with a component using canvas via a shadowroot. This runs fine with Dartium, "run as javascript" and pub serve. However when I run pub build and launch the html file in build/web, the component does not appear. The code is at
https://github.com/siddhartha-gadgil/mathlets
Should I be using some special transformers, or do something different to build as against serve?
I tried your project and it appears to be working fine.
What I have done in the past is run pub build and hit the built file in dartium and that will not work. So you have to hit the build file from chrome proper. So if I load .../mathlets/build/web/mathlets.html in chrome it works fine.
The reason for this is because pub build is the release build, which does not copy any of the dart files. However the index file still has the check if dart is enabled than try to use dart files. Well in dartium dart is enabled but the build doesn't have the dart files. In chrome dart is not enabled so then that 'packages/browser/dart.js' file dynamically writes the mathletes.dart.js to index and launches the app that way.
If you want to work around this and improve performance of the release build at the same time you can use this transformer: http://pub.dartlang.org/packages/dart_to_js_script_rewriter
We are using this also. Ensure it's the last transformer run though, if it's before the angular transformer there are problems.

how to solve this error on windows??? droidgap unrecognized

i download phonegap but it's bin folder just contain droidgap with unknown type.
when i use this command in command prompt with ruby droidgap wiz the result is :
droidgap is not recognized :(
i also install ant and sdk manager. and add their path to system path.i decide to use eclipse to build my android app(i write my app with js,css, html5). but when i make my app with eclipse browse button does not work & when i build it with phonegap browse button work. if you know solution please suggest it.
thanks in advane
That is actually a ruby executable file. To run droidgap you must have ruby installed.
refer here for installation of ruby https://www.ruby-lang.org/en/downloads/
and make sure that you set the path to ruby2.0.3/bin
here is the missing set up guide by phil http://dev.tonic1394.com/2010/06/phonegap-the-missing-androidwindows-setup-guide/

Resources