Dart Tutorial

Dart Tutorial Single-Page Application Architecture Dart Features Dart Installation Guide Dart Basic Program Dart Syntax Dart Keywords Dart Variables Dart Comments Dart Standard Input Output Dart Important Concepts

Data Types

Built-in Data Types Numbers Strings Booleans Lists Sets Maps Runes and Graphemes Symbols Enumerations Constants Queues

Other data types

Objects Future and stream Iterable Miscellaneous types

OPERATORS

Precedence and associativity Arithmetic operators Equality and Relational operators Type Test Operators Assignment Operators Logical Operators Bitwise and Shift Operators Miscellaneous operators

Control Flow Statements

Introduction If statement If-else statement If-else-if statement Loops Switch and case Dart Break And Continue Assert In Dart

FUNCTIONS

Dart function Types of Functions Anonymous function main( ) function Lexical scope and closure Recursion Common Collection Methods

Object Oriented Concepts

Dart Object-Oriented Concepts Dart Classes Dart Constructors Dart This Keyword Dart Super Keyword Static Members Method Overriding Dart Interfaces Inheritance Dart Abstract Classes Dart Builder Classes Dart Callable Classes

Dart Type System

Dart Type System Dart Soundness Dart Type Inference

MISCELLANEOUS

Dart Isolates Dart Typedef Dart Metadata Dart Packages Dart Generics Dart Generators Dart Concurrency Dart Unit Testing Dart Html Dom Dart URIs Dart Extends, With and Implements Keywords Dart Optional Parameters Rust Vs Dart C++ vs Dart Golang Vs Dart Dart Basics Exception Handling

Metadata in Dart

Metadata is often referred to as the data about the data. It is a  piece of data about a basic piece of data. In the case of a Dart program, metadata is also used to gain more perspective about the code. Whenever we correspond with a new piece of code, we can get the related information with the help of metadata.

With a dart metadata annotation starts with a ‘ @ ’ sign, followed by a call to a constant constructor or a compile-time such as an output. ‘@Override ’ and ‘ @deprecated ’ are available for all dart codes.

We will be going through an example of ‘ @override ’ annotation to understand it more clearly –

class meta
{
  void code( ) 
  {
    print( " Now you are inside the ' meta ' class. " ) ;
  }
}
class meta1 extends meta 
{
  @override
  void code( ) 
  {
    print( " Now you are inside the ' meta1 ' class. " ) ;
  }
}
void main( ) 
{
  meta1 m1 = new meta1( ) ;
  m1.code( ) ;
}

Output:

Now you are inside the ' meta1 ' class.

Explanation:

From the code above, we can clearly see that the child class is crossing the path of the parent class. The ‘ @override ’ annotation makes this information even clearer. In addition to the dart annotations, we can create our own metadata annotation.

Example:

class Implement {
  final String what ;
  final String by ;
  const Implement( this.what, this.by ) ;
}
@Implement( ' the following function ', ' J1 ' )
void Func( ) {
  print( ' Implement me ' ) ;
}  
void main( ) {
  Func( ) ;
}

Output :

Implement me

Here we explained the annotation of ‘ @Implement ’ using a constant constructor. In particular it has two arguments, namely what should be used and the other stating who will be used and by whom.

Metadata can be used before the library, type parameter, function, constructor, class, etc., and before the import or export command. We can get metadata during operation with the help of reflection.

Metadata Class

1. Methods

  • noSuchMethod( Invocation invocation ) -> dynamic

Invoked when a non-existent method or property is accessed. Classes can override ‘ noSuchMethod( ) ’ method to provide custom behaviour. If a value is returned, it becomes the result of the original invocation.

Implementation :

         dynamic noSuchMethod (

Invocation invocation

)

  • toString( ) -> String

Returns a string representation of this object.

Implementation :

external String toString( ) ;

2. Properties

  • modificationTime -> DateTime

Implementation :

DateTime get modificationTime =>

    convertNativeToDart_DateTime( this._get_modificationTime ) ;

  • size -> int

Implementation :

final int size ;

  • hashCode -> int

This property retreived hash code for the object invoking it.

Implementation :

external int get hashCode ;

  • runtimeType -> Type

A representation of the runtime type of the object.

Implementation :

external Type get runtimeType ;

3. Operators

The equality operator.

  • Operator ==( dynamic other ) -> bool

Implementation :

external bool operator == ( other ) ;