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
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
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
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
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
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 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
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
A function without a name is known as an anonymous function. They behave in the exact same manner as a normal named function would. The only difference between the named and an anonymous function is how different they are in syntax.Anonymous functions are used in Dart to form closures. An anonymous function contains a self-contained block of codes, also it can be passed as a parameter to another function as well.Anonymous function Syntax(parameterList){ // inner statement(s) }ExampleNow, let's consider a simple example of an anonymous function.Consider the example shown below − Live Demovoid main() { var fruits = ["Apple", ... Read More
Async and Await keywords are used to provide a declarative way to define the asynchronous function and use their results.The async keyword is used when we want to declare a function as asynchronous and the await keyword is used only on asynchronous functions.Syntaxvoid main() async { .. }If the function has a declared return type, then update the type of the Future to the return type.Future main() async { .. }And finally, we make use of await keyword when we want to wait for the asynchronous function to finish.await someAsynchronousFunction()ExampleLet's consider an example where we are declaring the main function ... Read More
 
 Data Structure
 Data Structure Networking
 Networking RDBMS
 RDBMS Operating System
 Operating System Java
 Java MS Excel
 MS Excel iOS
 iOS HTML
 HTML CSS
 CSS Android
 Android Python
 Python C Programming
 C Programming C++
 C++ C#
 C# MongoDB
 MongoDB MySQL
 MySQL Javascript
 Javascript PHP
 PHP