Found 33676 Articles for Programming

Hierarchical Inheritance in Dart Programming

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

2K+ 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

4K+ 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

4K+ 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

489 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

630 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

491 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

198 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

1K+ 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

754 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

Advertisements