Skip to main content

Dart Basic with Codes


Dart is a client-optimized programming language for apps on multiple platforms. It is developed by Google and is used to build mobile, desktop, server, and web applications. Dart is an object-oriented, class-based, garbage-collected language with C-style syntax. Dart can compile to either native code or JavaScript.
  Installation

3. install Dart plugin in IntelliJ IDEA
Basic Codes 

void main(){
print('Hello Rz');
}
Decision Making 
else if Statement
Electricity calculator 

import 'dart:io';
void main(){
var pre, cur, amt, units;
print ('Enter previous units :');
pre = int.parse(stdin.readLineSync());
print ('Enter current units :');
cur = int.parse(stdin.readLineSync());
units=cur-pre;
print('Consumed units: ${units}');
if (units==0){
print('You have to pay 50');
}else if(units>=1 && units<=100){
print('You have to pay ${units*05}');
}else if(units>100 && units<=200){
print ('You have to pay ${units*1.5}');
}else{
print ('You have to pay ${units*3}');
}
}
  
Nested IF Statement
Vote calculator 
import 'dart:io';
void main(){
var age, gender;
print('Enter your age: ');
age=int.parse(stdin.readLineSync());
print('Enter your gender');
gender=stdin.readLineSync();
if(age>=18){
if(gender=='M'||gender=='m'){
print('Go to Room No.5');
}else{
print('Go to Room No.7');
}
}else{
print('You are not eligible to vote');
}
}

objects and constructors
void main()
{
var superman = Hero('Clark'); //Create object
superman.myPower();//use of objects hero class
}

class Hero{
String name;
Hero(this.name); //constructor use in Dart

myPower(){
print('${name} can fly');
}
}


Comments