Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Types
  • Functions
  • Oops
  • Collections
  • Sets
  • Dart Interview Questions
  • Fluter
  • Android
  • Kotlin
  • Kotlin Android
  • Android with Java
  • Android Studio
Open In App
Next Article:
Dart - Basic Syntax
Next article icon

Dart - Basic Syntax

Last Updated : 27 Jun, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Dart is a static programming language developed by Google. According to the GitHub popularity index, it became the most popular programming language as it actually supports the flutter toolkit. Flutter is a framework that uses dart’s native compilation ability to generate fast cross-platform apps. Dart supports two types of compilation that are, Just in time and Ahead of time. Its syntax has basically a blend of CPP, Python, Java, and JavaScript. In this blog, We will look at the basic syntax in Dart and how to represent the language that the computer understands. We will see the basic structure of Dart programming. 

The syntax is a basic dart program that consists of various elements such as a keyword, an identifier, a constant, a string literal, data types, and symbols. Eg: to represent numbers words and even decimals we can call the type of data. Each line is dart must end with the semicolon.

Dart
void main() {      // declare and initialized a variable    int A = 2;    int B = 3;      // displaying the output   print( A + B );  } 

 
 

To represent this we can tell the type of the data, in the above example as an integer type. Similarly, To represent a word or string we can call the data type a string. All these are called Variables. Now the integers, strings, and even decimal values are temporarily held by a word or character like 'A' and 'B'. All these are called variables because the data inside can keep changing. The word to the left of the '=' is the variable while the one in the right is the actual value.


 

Comments in Dart

A comment is a code snippet that is not readable by the compiler. Comments help to write a code efficiently and make it easier to understand the code. Comments in dart can be obtained using one of the following:


 

' // ' is used to comment on a single line.  '/*.....*/ is used to comment on multiple lines.


 

Dart
void main() {      // Displaying the output   print('Hello, Geeks!');       /* print('Dart is a programming language');   print('Dart is a programming language'); */   print('Hello, Geeks!'); } 

 
 

Keywords in Dart:


 

Keywords are the words that are used a dart to represent the basics syntax that the compiler will understand. The basic keywords that are used in dart programs are listed below:


 

importelseasabstractswitchsuperin
enumassertexportconstvarvoidstatic
doasyncawaitcatchonnullnew
classbreakcontinuefalsenewtypedeftrue
gethidesetshowdynamicreturnrethrow

Apart from this, there are other keywords that can be used as the syntax, but they are rarely used.


 

Identifiers in Dart:

Identifiers are the name given to variables that can be read by the compiler. There are certain rules to write the identifiers:


 

  • No special symbol can be used except _ and $.
  • It can not be the reserved keywords.
  • There should not be any space between the variable name.
  • They are case sensitives.

Variables and Data types in Dart:

Variables are the name given to a memory location declaring by writing variable-type _ name and then initialized and declared by " variable-type name = value; ".


 

The dart language supports the following built-in types :


 

  • String


 

A Dart string is a collection of characters and letters. You can use either single or double quotes to create a string. For multi-line string, we can use '....' or ".....". We can give the value of a character inside a string by doing $ {expression}. 


 

Dart
var name = 'John'; 

 
 

Here a variable is called a name and the string is assigned a value "John".


 

Note: If a variable is not initialized then the default value is null 
  • Numbers 


 

Both int and double are can be used for the representation of numbers. These data types are used to represent any number and even a decimal. The num type operates with basic algebraic operators.


 

Dart
void main() {      // declare and initialized a variable    int A = 20;    double B = 30.0;      // displaying the output   print( A + B );  } 

 
 

  • Booleans


 

In order to use the Boolean data types, dart uses the keyword named bool. These data types have two values that are True and False.


 

Dart
void main() {  bool isIttrue1 = true;  print('$isIttrue1'); } 
  • Collection [List, Set, Maps]

Collections in Dart is basically a collection of similar and different data types. These are used as data structures in dart. Each element can be accessed sequentially.

Dart
void main() {   var list = [10, 20, 30];   var names = ['Jack','Jill', 10, 1]; } 

Operators in Dart:

Operators representation is really simple. The basic addition of numbers is possible by inserting the + operator. Similarly, we can insert any operators including BIT operation simply calling the operator on two values and assign it to another value. Let see some basics operators used in dart programming.

  • Algebraic Operators

These operators can be used between two values and assign to the third one. The operators are listed below:

  1. Addition -> "+" Operator
  2. Subtraction -> "-" Operator
  3. Multiplication -> "*" Operator
  4. Division -> "/" Operator
  5. Modular -> "%" Operator
  • Relational Operators

The below-listed operators are used to establish a relationship between two objects:

  1. Equal -> "==" Operator
  2. Not Equal -> "!=" Operator
  3. Greater than -> ">" Operator
  4. Less than -> "<" Operator
  5. Greater than or equal to -> ">=" Operator
  6. Less than or Equal to -> "<=" Operator
  • Logical Operators 

These operators are used to establish logic among objects or values. These operators are listed below:

  1. Logical AND -> "&&" Operator
  2. Logical OR -> "||" Operator
  3. Not -> "!" operator
  • Assignment Operators

The operators are used to assign values. These are listed below:

  1. Assignment -> "=" Operator
  2. Increment -> "+=" Operator
  3. Decrement -> "-=" Operator
  4. Product -> "*=" Operator
  5. Division -> "/=" Operator

=, +=, -=, *=, /= , etc  called as assignment operators.

  • Null Aware Operators

These operators are used to add Null aware objects. They are listed below:

  1.  ?
  2. ??
  3. ??=

Next Article
Dart - Basic Syntax

A

ashutoshprakash2455
Improve
Article Tags :
  • Technical Scripter
  • Dart
  • Technical Scripter 2020
  • Dart-basics

Similar Reads

    Swift - Basic Syntax
    Swift is a broadly useful programming language which is created by Apple Inc. It is an amazing programming language for iOS, iPadOS, macOS, tvOS, and watchOS. It incorporates present-day highlights engineers love. Swift code is protected by plan and furthermore delivers programming that runs lightni
    5 min read
    Dart - Basics of Set
    Set is a special type of collection in Dart programming. In which any object can occur only once. If we perform add operation in the set, if the object is already in the set then it will not add otherwise it will be added in the set.  dart: core library provides the Set class for implementation. Syn
    2 min read
    Dart - Basics of Packages
    The package is a set of Dart programs organized in an independent, reusable unit. Dart packages don’t include compiled code. The code is compiled when the app is built or run. Sample data may be included optionally by the package author. Dart comes with core libraries (not packages), automatically a
    2 min read
    Dart - Break Statement
    The break statement in Dart inside any loop gives you a way to break or terminate the execution of the loop containing it, and hence transfers the execution to the next statement following the loop. It is always used with the if-else construct. Dart Break Statement Flow DiagramWhile Loop: Do While L
    2 min read
    Basics of Numbers in Dart
    Like other languages, Dart Programming also supports numerical values as Number objects. The number in Dart Programming is the data type that is used to hold the numeric value. Dart numbers can be classified as: int (Integer) The int data type is used to represent whole numbers.Declaring Integer in
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences