Keywords in Dart
Dart Keywords are the reserve words that have special meaning for the compiler. It cannot be used as the variable name, class name, or function name. Keywords are case sensitive they must be written as they are defined.
Dart Keywords
There are 61 keywords in the Dart.
Some of them are common, you may be already familiar and few are different.
abstract
Abstract modifier is used to define an abstract class—a class that can’t be instantiated. Abstract classes are useful or defining interfaces, often with some implementation.
as
As operator is used to cast an object to a particular type if and only if when we are sure that the object is of that type.
assert
The assert statement is used to debug the code, and it uses boolean condition for testing. If the boolean expression in the assert statement is true then the code continues to execute, but if it returns false then the code ends with Assertion Error.
async
When an async function is called, a future is immediately returned and the body of the function is executed later. As the async function’s body is executed, the Future returned by the function call will be completed along with its result. In the above example, calling demo() results in the Future.
await
Await expressions makes you write the asynchronous code almost as if it were synchronous
break
Break is used for stopping the loop and switch case whenever the condition is met. Eg: Break in while loop
case
Case is the same as it is in other programming languages it is used with switch statement.
catch
Catch is used with the try block in dart to catch exceptions in the program.
class
Class in dart as same as a class in other object-oriented programming languages. A class is a group of objects which have common properties. It is a template or blueprint from which objects are created. It is a logical entity.
continue
Continue statement is used to break one iteration in the loop whenever the condition matches and start the next iteration.
const
Const is used for making a variable constant throughout the program. The const keyword isn’t just for declaring constant variables. We can also use it to create constant values and declare constructors that create constant values. Any variable can have a constant value.
covariant
Covariant keyword to tell the analyzer that you are overriding a parameter’s type with a subtype, which is invalid.This removes the static error and instead checks for an invalid argument type at runtime.
default
Default statement is used in switch case when no condition matches then the default statement is executed.
deferred
Deferred loading (also called lazy loading) allows a web app to load a library on-demand when the library is needed.
do
Do is used with while for do-while loop.
dynamic
Dynamic is used to declare a dynamic variable that can store any value in it be it string or int, it is the same as var in javascript.
else
Else is used with if statement, it is used to test the condition, if block is executed, if the condition is true otherwise else block, is executed.
enum
Enums, are a special kind of class used to represent a fixed number of constant values.
export
Export is used to create a new library and use other libraries you want to make available automatically when using your package.
extends
Extends to create a subclass, and super to refer to the superclass
extensions
Extensions are a way through which we can add functionality to the existing libraries.
external
An external function is a function whose body is provided separately from its declaration. An external function may be a top-level function or a method.
factory
Factory is used when implementing a constructor that doesn’t always create a new instance of its class.
false
False is one of the boolean types of dart apart from true.
final
Final is used when we don’t intend to change a variable in the rest of the program.
finally
Finally is a block, which is used to place codes that should be executed even if there is an exception in the program. finally block is placed after the try block and whenever any error occurs the control goes to the finally block and it is executed.
for
For is used in ‘for loop’, it is the same as for loops in other programming languages.
Function
Dart is a true object-oriented language, so even functions are objects and have a type, Function
. It means that functions can be assigned to variables or passed as arguments to other functions.
get
Getters and setters are special methods that provide read and write access to an object’s properties
hide
Hide is used when only part of a library, you can selectively import the library.