Found 56 Articles for Dart Programming

Future class in Dart Programming

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

338 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

466 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

341 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

74 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

Constructors in Dart Programming

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

674 Views

Constructors are methods that are used to initialize an object when it gets created. Constructors are mainly used to set the initial values for instance variables. The name of the constructor is the same as the name of the class.Constructors are similar to instance methods but they do not have a return type.All classes in Dart have their own default constructor, if you don't create any constructor for a class, the compiler will implicitly create a default constructor for every class by assigning the default values to the member variables.We can create a constructor in Dart something like this −class ... Read More

const keyword in Dart Programming

Mukul Latiyan
Updated on 21-May-2021 12:44:52

674 Views

Dart provides us with two ways in which we can declare variables with fixed values. One of them is by declaring a variable with a const keyword, and the other is by declaring the variable with a final keyword.It should be noted that both of them does provide an assurance that once a value is assigned to the variable with them, it won't change, but indeed they are slightly different from one another.constA variable that is declared using the const keyword cannot be assigned any other value. Also, the variable is known as a compile-time constant, which in turn means that ... Read More

Comments in Dart Programming

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

307 Views

Comments are a set of commands that are ignored by the compiler. They are used in a scenario where you want to attach a note to your code or a section of code so that when you visit it later, you can recall it easily.The comment statements are usually ignored during the execution of the program.There are multiple types of comments in Dart, mainly these are −Single line commentsMulti-line commentsDocumentation commentsWe will explore all the above document types in this article.Single Line commentsSingle line comments make use of // (double forward slash). They extend up to a new line character.Syntax// ... Read More

Cascade notation in Dart Programming

Mukul Latiyan
Updated on 21-May-2021 12:24:22

930 Views

Cascade notation is used when we want to operate a sequence of operations on the same object. The cascade notation is denoted by the (..) symbol.It is similar to method chaining that we have in other programming languages and it does save us plenty of steps and need of temporary variable.ExampleConsider the following example for a representation of how the cascade notation works in Dart. Live Democlass Sample{    var a;    var b;    void showA(x){       this.a = x;    }    void showB(y){       this.b = y;    }    void printValues(){     ... Read More

Break statement in Dart Programming

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

90 Views

The break statement is used when we want to break or terminate the execution of a loop. Once the break statement is reached the control is transferred from the current loop to whatever is written after the loop.It is mostly used in the conditional statement and also in loops of all types. It is present in almost all popular programming languages.Syntaxbreak;Now let's take a very simple example, where we have a variable named num and we are iterating until num > 5. Suppose we want to exit from the loop when we know that the value inside the num variable has ... Read More

Advertisements