What is Dart?

Dart is an object-oriented, open-source, client-optimized development programming language. It has C-styled syntax. It is used to create a good-looking front-end UIUser Interface for mobiles and the web. It is the foundation of Flutter.

DataTypes

Like C/C++, Dart also needs to declare DatatTypes of the variable during declaration. In Dart, we have the following:

  • int
  • bool
  • double
  • string
  • num
  • Map
  • List
  • custom objects

There are also some keywords that can also create variables. These are var, dynamic, final, and const.

Features of Dart language

Dart is very easy to learn. It is a new programming language created in 2017 by Google. Google developers put their efforts into developing this language for their cross-platform framework. Following are the main features of the Dart language that made it becomes so popular.

Null safety

Dart offers null safety. This means that variables cannot be null unless explicitly mentioned. With this feature, Dart protects developers from facing null exceptions during the execution of the source code.

Libraries

Dart has an extensive and excessive set of core libraries that helps developers with their everyday programming tasks. Following are some examples of Dart built-in libraries.

  • dart:core: This provides the core functionality of the program.
  • dart:html : This provides HTML and Document object model for web-based applicatios (DOM).
  • dart:math: This provides a mathematical functions library.
  • dart:collection: This provides data structures like queues, linked lists, maps, and trees.
  • dart:io: This provide files, sockets, and other Input output for client-server-based programs.

Documentation

Both Flutter and Dart have good documentation. With the help of a dartpad, we can become familiar with syntax so easily.

Note: To check the official documentation of Dart, click here

Community support

Dart is a programming language used in Flutter. The Flutter community supports programmers by answering queries, helping debug code, and organizing events. The community is still growing today.

Code

The following Dart program will take a number from the user and print a pattern of that height on the console.

import 'dart:io';
void main(){
// Taking input from user and typecast it to int
int rows = int.parse(stdin.readLineSync());
for(int i = 0 ; i< rows; i++)
{
for(int j = 0; j<=i;j++)
{
//Printing * on the console
stdout.write('* ');
}
// Print new line on the console
stdout.writeln();
}
}

Enter the input below

Copyright ©2024 Educative, Inc. All rights reserved