Immutability in Dart Programming

Mukul Latiyan
Updated on 21-May-2021 13:05:44

528 Views

Immutability is the ability to remain constant. Whenever we talk about immutability we mention the immutable nature.In object oriented and functional programming, we make use of the immutable nature of objects a lot. Being immutable means that the state of the object cannot be modified after its creation.It is a very important topic these days when we talk about front-end development, as there are several occasions and scenarios where we want to maintain the state and the way to do that is to make use of immutability.In Dart, there are different ways with which we can achieve immutability and sometimes ... Read More

If-Else in Dart Programming

Mukul Latiyan
Updated on 21-May-2021 13:05:22

149 Views

If statements are a major part of any programming language as they allow us to run things based on certain conditions, that's why they come under the conditional statements category.Dart's if-else statements follow the same syntax as Java's ones.Syntaxif( condition ) {    statement }If the condition in the above if parentheses evaluate to true, then the statements inside the code block will be evaluated.ExampleConsider the example shown below − Live Demovoid main() {    var age = 10;    if(age == 10){       print("10 is perfect");    } }Since in the above code the age == 10 evaluates ... Read More

Hierarchical Inheritance in Dart Programming

Mukul Latiyan
Updated on 21-May-2021 12:50:38

1K+ Views

Hierarchical inheritance is the case of inheritance when two classes inherit a single class.The syntactic representation of a hierarchical inheritance looks something like this −class A {} class B extends A {} class C extends A {}In the above syntactic representation, we can see that two classes, namely B and C are inheriting (or extending) class A.ExampleLet's consider an example of hierarchical inheritance in dart. Consider the example shown below − Live Democlass Parent{    void printName(){       print("Inside class Parent");    } } class Daughter extends Parent{    void age(age){       print("Her age is: ${age}"); ... Read More

Hello World in Dart Programming

Mukul Latiyan
Updated on 21-May-2021 12:50:00

3K+ Views

A Hello World program is the first program that you learn whenever you are learning a new programming language. It might be a simple program but it is a great entry point as you get to know how a program works in Dart, how to run a dart file. It provides a way to test the systems and environment that you are using.An important prerequisite before running a Hello World in Dart is to have the Dart SDK installed on your local machine. You can install the Dart SDK from this link.Writing Hello World ProgramThe first thing that you need ... Read More

Getter and Setter in Dart Programming

Mukul Latiyan
Updated on 21-May-2021 12:49:35

3K+ Views

Reading and writing access to objects is very important in any programming language. Getter and Setter are the exact methods that we use when we want to access the reading and writing privileges to an object's properties.SyntaxA getter usually looks something like this -returnType get fieldName {    // return the value }The returnType is the type of data we are returning. The get keyword is what tells us and the compiler that is a getter, and then lastly we have the fieldName whose value we are trying to get.A setter usually looks something like this −set fieldName {    // set the ... Read More

Future class in Dart Programming

Mukul Latiyan
Updated on 21-May-2021 12:47:28

346 Views

There are different classes and keywords in Dart which we can use when we want to run Asynchronous code. The future class allows us to run asynchronous code and we can also avoid the callback hell with the help of it. A future mainly represents the result of an asynchronous operation.In Dart, there are many standards library calls that return a future, some of them are −http.getSharedPreference.getInstance()A future in Dart can have two states, these are −Completed - When the operation of the future finishes and the future complete with a value or with an error.Uncompleted - When a function is called, and it ... Read More

Functions in Dart Programming

Mukul Latiyan
Updated on 21-May-2021 12:47:04

470 Views

Dart is a true object-oriented programming language. Even functions have their type in dart. Functions can be assigned to a variable and we can even pass them to another function as well. Functions in Dart are also objects, like everything else.Let's create a simple function that accepts an integer as an argument and returns a bool value.ExampleConsider the example shown below −bool isOdd(int x){    return x % 2 == 1; } void main() {    bool ans = isOdd(3);    print(ans); }In the above code, we have two functions, one is the main() function whose return type is ... Read More

final keyword in Dart Programming

Mukul Latiyan
Updated on 21-May-2021 12:46:38

3K+ Views

The final keyword in Dart is used to create constants or objects that are immutable in nature. The only difference between the final and const keyword is that final is a runtime-constant, which in turn means that its value can be assigned at runtime instead of the compile-time that we had for the const keyword.ExampleConsider the example shown below − Live Demovoid main(){    final int xy = 10;    print(xy); }Output10In the above example, we declared an int variable with a final keyword, which means that the value once assigned to it won't change.ExampleConsider the example shown below −void main(){   ... Read More

Enumerations in Dart Programming

Mukul Latiyan
Updated on 21-May-2021 12:46:13

347 Views

An enumeration is a set of predefined values. These values are known as members. They are useful when we want to deal with a limited set of values for the variable. For example, you can think of the number of days in a week - Monday, Tuesday, Wednesday etc.An Enumeration can be declared using the enum keyword.Syntaxenum {    const1,    const2,    ….    constN }Let's define an enumeration for the number of colors in a traffic light −enum TrafficLights {    Red,    Green,    Yellow }Now, let's see how we can make use of an enumeration in ... Read More

Continue statement in Dart Programming

Mukul Latiyan
Updated on 21-May-2021 12:45:50

76 Views

The continue statement is used when we want to skip over the current iteration of any loop. When the compiler sees a continue statement then the rest of the statements after the continue are skipped and the control is transferred back to the first statement in the loop for the next iteration.It is used in almost every programming language and we normally encounter continue statements inside the conditional blocks of code.Syntaxcontinue;ExampleLet's consider an example where we make use of a continue statement inside the while loop.Consider the example shown below − Live Demovoid main(){    var num = 10;    while(num >= ... Read More

Advertisements