In this post, our agenda will be to focus on variables and data types in dart and a few fundamental concepts that should be kept in mind.

You can declare a variable with the keyword ‘var’ and 'dynamic' in the dart.

Example # 1

Alt Text

where name is a variable that stores a string value, you can override the value with an integer or any other type of value.

Alt Text

You can also use type for a variable. In the above example, "myName" is a variable of String that can only store string values and if you try to override the value with a different type of value you will get a warning.

You can also use keywords like final, const, and dynamic to create a new variable. final and const are used to declare a variable whose value cannot be modified later.

Example with "final":Alt Text

Example with "dynamic":Alt Text

All variables in dart are a reference to objects which contain values and actions.

Dart contains six special types that are-

  • Integers
  • Floating-point numbers
  • String
  • Lists
  • Maps
  • booleans

We will go in-depth on types in the next article. Let me know if you like or dislike the article. I will improve upon the suggestions and feedbacks.

Happy learning, stay healthy and stay safe, thank you!!

This post is also available on DEV.