Found 55 Articles for Dart Programming

while and do-while in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:23:52
While and do-while loops are also present in Dart's arsenal. They are quite similar in terms of syntax and functionality to the C's while and do-while loops.While loopA while loop is an indefinite loop that can be modified to run for a finite number of iterations based on the condition we provide.Syntaxwhile(condition){    // do this }ExampleConsider the example shown below − Live Demovoid main() {    var age = 6;    while(age < 10){       print("age is now $age");       age++;    } }Outputage is now 6 age is now 7 age is now 8 age ... Read More

Variables in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:23:21
Dart being a statically typed language demands that we declare the type of variable that we going to use. In simpler terms, it is necessary that we define what kind of data we are going to store in the variable before making use of it.ExampleConsider the example shown below − Live Demovoid main(){    int collegeId = 1234;    // declaring and assigning a variable    print(collegeId);        // printing the variable's value    String myName = "mukul";    print(myName); }In the above example, we declared two variables named 'collegeId' and 'myName' and assigned 1234 and "mukul" as ... Read More

Typedef in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:22:56
In Dart, we make use of Typedef when we want to create an alias for a function type that we can use as type annotations for declaring variables and return types of that function type.A typedef holds type information when a function type is assigned to a variable.Syntaxtypedef functionName(parameters)We make use of the above syntax when we want to create a Typedef in Dart.Now, let's take a look at an example when we want to assign a typedef variable to a function in a program.typdef varName = functionNameOnce we have assigned the functionName to a typedef variable, we can later invoke the original ... Read More

This keyword in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:22:32
This keyword in dart is used to remove the ambiguity that can be caused if the class attributes and the parameters have the same name. This keyword basically represents an implicit object pointing to the current class object.We usually prefix the class attribute with this keyword whenever we want to remove the ambiguity between the class attributes and the parameters.ExampleLet's take two examples of the case where the name of the class attribute and the parameters are the same.Consider the example shown below − Live Demovoid main() {    Employee emp = new Employee('001');    emp.empCode = '111'; } class ... Read More

Test type operators in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:21:49
There are certain cases where we want to check if a variable is of a certain data type or not. Dart provides two test type operators that we can make use of.These two test type operators are −is - return true if that variable of the type we are checking againstis! - return true if that variable is not of the type that we are checking against.SyntaxThe syntax of is operator looks something like this −x is intIn the above example, x is the name of the variable and we are checking whether x is of data type int.The syntax ... Read More

Ternary Operator in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:21:25
The ternary operator is a shorthand version of an if-else condition. There are two types of ternary operator syntax in Dart, one with a null safety check and the other is the same old one we encounter normally.Syntax 1condition ? expressionOne : expressionTwo;The above syntax implies that if a certain condition evaluates to true then we evaluate the expressionOne first and then the expressionTwo.ExampleLet's explore a Dart example where we make use of the above syntax of the ternary operator.Consider the example shown below − Live Demovoid main(){    var ans = 10;    ans == 10 ? print("Answer is 10") ... Read More

Switch statements in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:21:02
Switch statements help us in cases where we want to run specific code based on certain conditions. It's true that if-else conditions also help us in the same section of code, but the switch statements reduce the complexity of the program as we will end up with less code in case of a switch if the condition checks are dense.Syntaxswitch(case){    case x:       // do something;       break;    case y:       // do something;       break;    default:       // do something; }ExampleConsider the example shown below − Live ... Read More

Super keyword in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:20:36
Super keyword in dart is used to refer to the parent's class object's methods or variables. In simple terms, it is used to refer to the superclass properties and methods.The most important use of the super keyword is to remove the ambiguity between superclass and subclass that have methods and variables with the same name.The super keyword is able to invoke the parent's objects method and fields, as when we create an instance of the subclass in Dart, an instance of the parent class is also created implicitly.Syntaxsuper.varName or super.methodNameAs we can access both the variables and methods of the parent's ... Read More

Super constructor in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:19:58
The subclass can inherit the superclass methods and variables, but it cannot inherit the superclass constructor. The superclass constructor can only be invoked with the use of the super() constructor.The super() constructor allows a subclass constructor to explicitly call the no arguments and parametrized constructor of superclass.SyntaxSubclassconstructor():super(){ }Though, it is not even necessary to use the super() keyword as the compiler automatically or implicitly does the same for us.When an object of a new class is created by making use of the new keyword, it invokes the subclass constructor which implicitly invokes the parent class's default constructor.Let's make use of an example where ... Read More

String Properties in Dart Programming

Mukul Latiyan
Updated on 24-May-2021 12:19:26
Strings in Dart have certain properties attached to them. These properties come in handy in different use cases.The most common used string properties are −hashCodeisEmptyisNotEmptylengthrunesIn this article, we will explore all the above mentioned properties of a string.hashCodeThe hashCode property of a string is used to print the hashCode number of the specific string on which it is called.ExampleConsider the example shown below − Live Demovoid main(){    String name = "Tutorials Point";    print(name.hashCode); }Output147510269isEmptyThe isEmpty property of a string returns true when the string is an empty string.ExampleConsider the example shown below − Live Demovoid main(){    String name = "Tutorials Point"; ... Read More
Advertisements