loading...
Cover image for Data Types in Dart

Data Types in Dart

jay_tillu profile image Jay Tillu😎 Updated on ・3 min read

Data type means the type of data that can be represented and manipulated in a programming language. Let’s see how dart represents data types.

Dart supports three types of data type. They are represented in a very simple and concise manner. (Let’s keep List and Maps aside for collection part.)

  1. Numbers
  2. Strings
  3. Boolean
  • NOTE:- Although Dart is strongly typed, type annotations are optional because Dart can infer types.

When you want to explicitly say that no type is expected, use the special type dynamic.

Numbers


Note: Number representation in dart may vary from platform to platform. That means if you deploy your code on DartVM then the size will be different and if you deploy your code on browser then the size will different. For example, take a look at *int**.

  • Numbers in dart are used to represent numeric literals.

Numbers can be divided into two parts.

  • Integer
  • Double

Integer

An integer used to represent 64-bit non-frictional values (numeric values without a decimal point). Integer literals are represented using int keyword.

  • Ex: — 10, 20, 30, 400, 50 etc

Size of int

  • On DartVM — [-2⁶³ to 2⁶³-1]
  • On browser — [-2⁵³ to 2⁵³-1] (Where number system must be compatible with JavaScript)

Double

Double used to represent fractional values (numeric values with a decimal point). Double literals are represented using double keyword.

Double data type in dart represents a 64-bit (double precision) floating-point number.

  • Ex: — 10.20, 20.40, 30.50 etc.

As of Dart 2.1, integer literals are automatically converted to doubles when necessary. Before Dart 2.1, it was an error to use an integer literal in a double context.

Strings


The string represents a sequence of characters. For example, if you want to store some data like name, address, country name, etc. Then you can use a string data type.

By default, string uses UTF-16 code units but you can use UTF-32 code units as well by using runes.

The keyword String used to represent string literals.

You can use single or double quotes for embed string. We’ll discover more about strings in a dedicated post.

Boolean


The Boolean type represents a boolean (flag) values.

bool keyword used to represent boolean values.

Boolean values are true and false. They must be written in lower-case. You cannot use 0 or 1 to represent true or false.

That’s all you need to know about data-types in the dart. Feel free to let me know if I missed something. I’ll Love to learn that.

Till then Keep Loving, Keep Coding.☺️

Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitate that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.

For More Information Please Visit Following Links

Wanna get in touch with me? Here are the links. I’ll love to become your friend. 😊

Posted on by:

jay_tillu profile

Jay Tillu😎

@jay_tillu

🌏 विधायास्य धमॅस्य संरक्षणम् 🌍 ☀️ Society before Self ☀️ 🙏🏻 Humanism by Religion 🙏🏻 💻 Work for Mankind 💻 🌐 Believes in वसुधैव कुटुम्बकम् 🌐

Discussion

pic
Editor guide