Dart Programming - SkillBakery Studios

Breaking

Post Top Ad

Post Top Ad

Sunday, August 30, 2020

Dart Programming

 

Dart is an open-source, general-purpose programming language.it is originally developed by Google and later approved as a standard by ECMA.it supports a various range of programming aids like interfaces, classes. Dart is used to creating a single-page web application. we take an example of twitter as a single page application where browser stays on the same web page and javascript code changes. Dart compiled to fast native code and allows flutter to be written in dart and thus making flutter faster. Dart create smooth animations.

Dart can allocate objects and garbage collection without locks. Developers believe dart is easy to learn because of its features which can be used in any language. Dart is for both server and browser. Dart SDK ships with its compiler –the Dart VM.

This blog post will help you learn the basics of dart programming.

This is very much useful for those developers who want to develop single-page web application using Dart. Dart will be easy for those who have command over oops concepts.

Prerequisites to learn Dart

·        Knowledge of JavaScript

·        Good command over object-oriented programming concepts.

Dart Environment

Dart editor executes scripts and displays the output in both HTML and console.you can use the online editor to test your code.online editor has preset code samples.

 Dartpad Editor


Dartpad enables code in a more restricted form. We can check this by clicking on a strong mode option on the bottom right of the editor.

 Let’s see a simple example using Dartpad

 [code]

 Void main()

 {

 print(‘hello world’);

 }

 [/code]

 Output

 Hello World

 How to setup your local Environment

 Using text editor

 We can use different text editors for e.g windows,notepad,notepad++,Ernacs.Only we have to   save and name the source file with the extension “.dart”.

 Installation process

We can download the stable version of dart.the dart sdk can be downloaded from

http://www.dartlang.org/install/archieve

on completion of the installation, we should set the PATH environment variable to <dart-sdk-path>\bin

How to check and verify the installation

Check with the command prompt and enter

Dart

After the successful installation, it will show the dart runtime.

Dart Syntax

Syntax is basically a set of rules for writing programs. Every language defines its own syntax,  a dart is composed of

·       Variables and operators

·       Classes

·       Functions

·       Expressions and programming constructs

·       Decision making and looping constructs

·       Libraries and packages

Your first Dart Code

 [code]

main()

{

print(“hello world!”);

}

 [/code]

main() function is a predefined method in dart. A dart script needs the main() method for execution.print() is a predefined function that prints the value.

Output of the code

Hello, world!

 

Dart classes and objects

Dart is an object-oriented programming language, so for the concept of class and object we use the class keyword to do so

Class  class-name

{

//body of class

}

Dart classes are the blueprint of the objects. A class can contain fields, functions, and constructors, etc. class can refer to a user-defined data type which defines characteristics by all its objects.

Let’s define a class in Dart

Dart provides class keywords followed by a className. All fields and functions are enclosed in {} braces

[code]

Class className

{

<fields>

<getter/setters>

<constructor>

<functions>

}

[/code]

In curly braces, we provide a class definition. A class of fields, constructors, and methods.

For e.g

[code]

void main()

{

Class Student

{

var stuName;

var stuAge;

var stuRollNo;

ShowStuDetail()

{

print(“student Name is : ${stuName}”);

print(“student Age is :${stuAge}”);

print(“student Roll No is :${stuRollNo});

}

[/code]

Instance Variable and Function

After creating an object, we access the fields and methods of the class. Class property name is separated by (.)

ObjectName.propName

E.g.

[code]

Class Student

{

var stuName;

var stuAge;

var StuRollNo;

ShowStuDetail()

{

print(“Student Name is : ${stuName}”);

print(“Student Age is  :${stuAge}”);

print (“Student Roll No is :${stuRollNo}”);

}

}

void main()

{

var stu = new student()

Stu.stuName =”Bhawna”;

Stu.stuAge=”36”;

Stu.stuRollNo =”101”;

Stu.ShowStuDetail();

}

Output is

Student Name is: Bhawna

Student Age is:36

Student Roll No is:101

 [/code]

Dart Operators

Operators are a symbol used to manipulating the values or performing the operations. Dart has build-in operators to accomplish different types of operations.operators can be unary or binary.

Different types of operators

·       Arithmetic operators

·       Assignment operators

·       Relational Operators

·       Type-text Operators

·       Logical Operators

·       Bitwise Operators

·       Conditional Operators

These are some basics to start with Dart. Most importantly dart is used for product development in which it’s easy to make changes to your source code alternatively using hot reload and see the results instantly.

Dart provides a flexible type system with rich configuration tools. With dart we can do logging,debubbing with your choice of code editor.

Dart works faster on all platforms.you can write simple scripts and with the flexible compiler technology dart lets you run your code much faster.

The most important in all are

Dart Native includes both Dart VM with Just In Time compiler and AOT(Ahead Of Time)compiler to change it to machine code.

Dart Web includes both development time compiler(dart-devc) and a production time compiler(dart2js).Dart dev compiler is a dart-to-javascript compiler that has quick turnaround.

 Who Uses Dart?

Flutter the most popular toolkit uses dart as the programming language .developers writing flutter app uses dart to make a user interface beautiful and interactive.


No comments:

Post a Comment

Post Top Ad