DEV Community

Cover image for 1/100DaysOfFlutter : Dart Basics - Final v/s Const
Abhay Prajapati
Abhay Prajapati

Posted on

3 2

1/100DaysOfFlutter : Dart Basics - Final v/s Const

1/100DaysOfFlutter : Dart Basics/Final v/s Const

Variables in dart

  1. var: variable can be reassigned.
  2. final: variable can not be reassigned.
  3. const: constant variable.

Different between Final and Const

in a easy way

final name;βœ…
// you assign value of final after declaration.
name = 'Dart'; βœ…

// NOT POSSIBLE WITH DART
const pi;❌
// ERROR: cannot initialize const variable, assign a value to it.
const pi = 3.14;βœ…
Enter fullscreen mode Exit fullscreen mode

How dart code starts;

void main() {
  print('Hello World');
}
Enter fullscreen mode Exit fullscreen mode

in dart code, the Main function is the entry point of the program

1. You wan to print something on the console; start with main().
2. You want to return something; start with main().
3. main() is starting.
Enter fullscreen mode Exit fullscreen mode

What is dart?

Dart is Static language; which meaning everything thing should have a type.
Name, Place, Animal, things
any things/ everything should have a type.

String name = 10;
int age = 10;
Enter fullscreen mode Exit fullscreen mode

print in dart.

print('1/100DaysOfFlutter : Dart Basics');
Enter fullscreen mode Exit fullscreen mode

String Interpolation in dart

this feature helps us to use variables in dart

void main(){
    String name = 'Dart';
    print("Hello $name");
}
Enter fullscreen mode Exit fullscreen mode

Taking input in console.


import 'dart:io';

void main(){
    stdout.write('Enter your name: ');
    String? name = stdin.readLineSync();
    // currently ignore "?"
    print('Hello $name');
}
Enter fullscreen mode Exit fullscreen mode

Data Types πŸ™ˆπŸ™‰πŸ™ŠπŸ΅ in dart:

Number: int, double, num
String : String
Boolean: bool (True or False)
List: List (Array)
Map: Map (Dictionary/ Object)
Null: null
Dynamic: fancyname
Void: void/nothingβ›”
Function: Function/πŸ€–

🀝🏾Connect me on:
Twitter: πŸ•ŠοΈ@Abhayprajapati_
Github: 🐧@theabhayprajapati
Linkedin: πŸ“Œ@abhayprajaapati
Youtube: πŸ“Ί@Abhayprajapati

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (1)

Collapse
 
reng99 profile image
call me R β€’ β€’ Edited

100th article of flutters, I will make an eye on THAT. πŸ’¨

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay