DEV Community

Flutter Tanzania
Flutter Tanzania

Posted on

Hello Dart World 😜

Dart is a general purpose programming language that is developed and maintained by Google. With dart one can develop web, server, desktop and mobile applications for iOS and Android.

Dart is easy to learn, and if you came from C-style languages or object oriented it will be easy to pick up, but if your a beginner in programming then Dart is a good place to start with. One exiting thing about dart is that you can build applications in multiple platforms using a single code base.

In this first article series will focus on setting up environment and write our first dart Hello, let's get in 🚀.

Setting up Dart environment:

There are several options that we can use to run Dart to, so first let's look at them.

  • DartPad: It's a simple browser based tool for writing and running Dart code. It's available in any modern web browser you can access it in https://dartpad.dev.

  • Visual Studio Code: This is a most used IDE which also supports Dart development by proving Dart extension. We recommend using this tool but if you have another tool you can go with it also.

There many other tools that you can use to run Dart but in our article series we will be using VS Code, you can use any of your preferred IDE.

Installing VS Code
Visual studio code is an open source and cross platform IDE which is maintained by Microsoft and it's available in MacOS, Windows and Linux.

Download Visual Studio Code at code.visualstudio.com, and follow the directions provided on the site to install it.

To run Dart in VS code we need to install Dart SDK first, let's do it.

Installing Dart SDK

Dark SDK is a collection of command line tools that makes it possible to build Dart program.

To install Dart SDK visit https://dart.dev/get-dart and you can follow instructions from the site to complete it's installation.

After you have installed Dart you can run the following command to ensure that everything runs.

dart --version
Enter fullscreen mode Exit fullscreen mode

This command will display your current version of Dart.

Let's explore some of the command that dart offers us and their use. Run the following command.

dart help
Enter fullscreen mode Exit fullscreen mode

This command will list available commands that we can use in dart.

  • analyze: this command analyses your code and tell when you have made a mistake in your code.

  • compile: this command complies Dart code into a native executable program for Windows, Linux or MacOS.

  • create: it's used for creating new dart project.

  • fix: This command applies automated fixes to your dart code from syntax and more.

  • run: this command is use to run your dart file to produce the output.

  • test: this command is for performing unit test in your dart project.

Dart comes with many other command that you can use, to learn more about them you run dart help and explore them.

Write our first code

Now let's write our first line of code, but first let's start by creating a Dart project.

Go the computer location where you want to run your project and run the following command.

dart create hello_dart
Enter fullscreen mode Exit fullscreen mode

This will create a new directory named hello_dart which contains our project files. Navigation to the project by writing cd hello_dart in the command.

To run our first dart project we will run the following command.

dart run hello_dart.dart
Enter fullscreen mode Exit fullscreen mode

What was the output?

A dart project contains the following list of files

  • bin: this directory contains all of our executable files

  • hello_dart.dart: which is named as the same name of the project, this file contains Dart code to execute.

  • pubspec.yaml: pubspec.yaml: Contains a list of the third party Pub dependencies you want to use in your project.

  • README.md: This describes what our project is about and how it's organized.

  • analysis_options.yaml: Holds special rules that will help you detect issues with your code.

  • .gitignore: Lists all files that won't be needed when your uploading your files in git repository.

And that's for this article, but don't stop here you can search online for another resources and learn more about dart.

In our next article we will focus on Expressions, Variables & Constants, see you then.

Top comments (0)