Quick Learn Dart Language
Quick Learn Dart Language
Category: Skill Learning Tutorials
Larnr Education | 2190views

If you are new in flutter development then you must know the Dart programming language. This programming language was developed by Google in the year of Oct 2011. Dart is a programming language designed for client development, such as for the web and mobile apps. You can also be used to build server and desktop applications. Dart is an object-oriented, class-based, garbage-collected language with C-style syntax. But Some Syntaxes are inspired by Python and PHP also. 

1. Why Learn Dart Programming Language?

Ans: If you are an absolute beginner and you want to start learning about programming language. then Dart Programming Language is the Best for you. Because This Programming language is simple and it is also object-oriented language. Once you will learn it, you have the proper programming language knowledge, which helps you grow yourself as a programmer quickly. 

2. Is it an easy programming language?

Ans: Yes, You can learn it easily it is like JavaScript as well as C or Java-based coding styles also here in this programming language.

3. After Learning This Programming Language What Can I Do? How can use it?

Ans: If you are CS Student, Then it is very easy to learn for you. If you are not then you just focus on learning. This article will be helping you understand the dart programming language. 

And After Learning this programming language you can learn the flutter framework for mobile applications. But flutter is supported with Desktop OS, Mobiles OS and Website Applications also. Almost everything you can be developed. 

So now we can discuss Dart Programming Topics.

When we are learning any programming language. That time you must-have pieces of knowledge on some programming features. Which is most essential. 

Programming Syntax and Features:

Variables - It is the primary part of all programming languages, Variables takes ram location for value storing. And its help to process the programmings.

Array Variables - When we wanted to store multiple values in one variable. That time we can use Array in our programming language.

// Number Type
int a = 12; // Whole Number
double b = 2.2; // Decimal Number
num c = 34.456; // Any type of number can store.

// Multiple Character type called String
String name = 'Joy';

// Check data type called Boolean
bool check = true; // It used like true / false

// Array data types
List<String> names = ['Ram', 'Shyam', 'Jadu', 'Madhu'];

// Dynamic data type you can store any type of value in this
var age = 10; // here you use 
//var price = 12.5; var name= 'Ram', var names=['Ram', 'Shyam', 'Jadu', 'Madhu']

Conditions and Loops - It is very helpful for your programming implementations. Like if you are writing some programs that time you must implement some real-time actions and processes which is called business logic. that time will be used conditions and loops for that process.

When we are working on Software Programming that time we need some Operators. Also, have some operator types. Like- Assignment Operators, Mathematical Operators, Logical Operators and Bitwise Operators.

= Assignment Operators
+= Additional Assignment
-= Subtraction Assignment
*= Multiply Assignment
/= Divisional Assignment
%= Modulus Assignment

 
Mathematical Operators
+, -, *, /, %

Compareation / Logical Operators
== Equal
!= Not Equal
< Less Than
> Grater Than
<= Less Equal Than
>= Grater Than Equal

++ Increment Operator
-- Decrement Operator

Logical Syntax is also important 
if, if...else, if...else if...else, switch...case, (?:) Turnary Operators

Loop Syntax
while, do...while, for, for...in 

Conditional Programming Examples.

// Program is If you have more than 50 rupees then you can rides Bus or You can choose Train.

var amount = 51; // Value Initilization 
if(amount>50){ // Condition Check
 print('You can ride to Bus.'); // If Condition is true
}else{
 print('You can ride to Train.'); // If Condition is false
}
//Like This, you can write more programs using logical syntax.

// Program is If you have more than 50 rupees then you can ride Bus or If you have more than 10 rupees You can choose Train otherwise you don't go.

var amount = 51; // Value Initilization 
if(amount>50){ // Condition Check
 print('You can ride to Bus.'); // If Condition is true
}else if(amount>10){
 print('You can ride to Train.'); // If next Condition is true
}else{
 print('You don't go.'); // If all Condition is false
}

//This is another sample.

// Also, You can use the same program using switch...case

var amount = 50; // Value Initilization 
switch(amount){
 case 50: { print('You can ride to Bus.'); }
  break;
 case 10: { print('You can ride to Train.'); }
  break;
 default: { print('You don't go.'); }

// Note This time amount value need to exact match with the case value

// Now we can see ternary operator use
var output = (amount>50)? 'You can ride to Bus.' : 'You can ride to Train.';
print(output); // It is single line condition checking syntax 

Loop Programming Examples:

// When we want to get continue output from programs with other values. That time we are use loops.
// You wants to get output the value of level 1 to level 10. that time how can use loop syntax.

var i = 0; // Initial Value
while(i<10){ // Condition Chek
 print('Level: '+i); // Output
 i = i + 1; // Increments, It is must be required. completing this.
}

var i = 0; // Initial Value
do{
 print('Level: '+i); // Output
 // i = i + 1; // Increments, It is must be required. completing this.
 i++; same like avobe syntax
}while(i<10); // Condition Chek

// in the for loop use syntax for(initialization; condition; increment/decrement){ statement / output }
for(var i=0; i<10; i++){
  print('Level: '+i);
}

// When you are using Array / List / Map variables that time you can use for...in loop
List<Sring> names = ['Ram', 'Shyam', 'Jadu', 'Madhu'];
for(String name in names){
  print('Hello '+ name);
}
// Get output: Hello Ram, Hello Sha... like this. 

Functions - When we write the Same types of Codes for Multiple outputs for the same purpose. I mean If you wanted to do Sum with 4+5 = 9, But you want the same sum for 9+5=?. This time you just write one simple function declared sum as a function after then you just put arguments or params for the sum functionality

//Declared The Function
// int a or int b called as arguments or parameter
void sum(int a, int b){
  int c = a+b;
  print('Sum:'+ c);
}

// Call this function
// main function is required for every programs
void main(){
 sum(4,5); //Output: Sum: 9
 sum(9,5); //Output: Sum: 14
}

Object-Oriented Programming: This is the very essential feature of every programming language. When we want to develop software programs. that time we must use  OOP concepts in our programs.  If I detail discussed with Object-Oriented Programming Then Another Single article can write on this topic.

// OOPs Features is
// 1. class
// 2. object
// 3. Inheritance
// 4. Polymorphism
// 5. Encapsulation
// 6. Interface or abstraction
// 7. Mixin

// Interface class have Unimplemented function/method
// This class used as interface 
class Action {
  // Unimplemented Method
  void goSpeed();

  noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}

// This class also Interface class
class Action1 {
  // Unimplemented Method
  void start();
  void run();
  void stop();

  noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}

// This class also Interface class
class Action2 {
  // Unimplemented Method
  String getInfo();
  void info();

  noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}

// It is the Mixin class but it can not create any object, 
// It only used for Supported parts for another class.
mixin Actionable implements Action, Action1, Action2 {
  int wheels = 4;
  String color = 'black';
  String model = 'Car';
  bool isStarted = false;
  bool isRunning = false;

  void start() {
    if (isRunning == false && isStarted == false) {
      print(model + ' is started.');
      isStarted = true;
    }
  }

  void run() {
    if (isStarted) {
      print(model + ' is running.');
      goSpeed();
      isRunning = true;
    } else {
      print(model + ' is not running. Because ' + model + ' is not started.');
    }
  }

  void stop() {
    if (isRunning == true && isStarted == true) {
      print(model + ' is stopped.');
      isStarted = false;
      isRunning = false;
    } else if (isRunning == false && isStarted == true) {
      print(model + ' is started. But ' + model + ' is not running.');
      print(model + ' is stopped now.');
      isStarted = false;
    } else {
      print('Please start the ' + model + '.');
    }
  }
}

// It is also Mixin class
mixin Actionable1 {
  int wheels = 4;
  String color = 'black';
  String model = 'Car';

  String getInfo() {
    return 'Model name: ' +
        model +
        ', Color: ' +
        color +
        ', Wheels: ' +
        wheels.toString();
  }

  void info() {
    print(getInfo());
  }
}

// This class is an abstract class. This class can not create any object.
abstract class Car with Actionable, Actionable1 {}

// This is the Exteded class. It is called Inheritance 
class Honda extends Car {
  String model = 'Honda Car';
  String color = 'blue';
  String price = 'Rs. 25Lac';
  int topSpeed = 120;

  @override
  String getInfo() {
    return super.getInfo() + ', Price: ' + price;
  }

  @override
  void goSpeed() {
    print(model + ' have top speed upto ' + topSpeed.toString() + 'km/h');
  }
}

main() {
  // Class Object Creation Process
  var car = Honda();
  car.start();
  car.run();
  car.stop();
  car.info();
}

Extra Features:

Async and Await for Future Data - These are the most important features for dart language. This programming language was developed for client optimized UI design purposes. And this language has also server-side app development. When we are calling API services that we must be used these features.  Get Know from example code:

// Data Generators
Future<String> getDate() {
  return Future.delayed(Duration(seconds: 2), () => 'Some Future Data');
}

// Data Receivers
Future<void> showData() async {
  var data = await getDate();
  print('Data is ' + data);
}

// Data uses
void main() {
  print('Start');
  showData();
  print('End');
}

Streaming Data - When we wanted to make any kind of real-time data communication application. that time we need to use this feature. Using these features we can make chat applications, online video and audio streaming services etc.

// Create Stream Data
Stream<int> createNums() async* {
  for (int i = 0; i <= 10; i++) {
    yield i;
  }
}


// Receive Stream Data
Future<void> showData(Stream<int> stream) async {
  int total = 0;
  await for (int number in stream) {
    total += number;
  }

  print(total);
}

main() {
  showData(createNums());
}

This is the all about Dart Programming Language. In this article, you understand dart programming.  If you thought this tutorial is helpful. then do like, share this content.