{"id":19819,"date":"2022-05-27T05:01:06","date_gmt":"2022-05-27T05:01:06","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=3874"},"modified":"2022-05-27T05:01:06","modified_gmt":"2022-05-27T05:01:06","slug":"dart-metadata","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/05\/27\/dart-metadata\/","title":{"rendered":"Dart Metadata"},"content":{"rendered":"\n<p>The Dart Metadata is used to specify the Dart program with additional information. It usually starts with @ symbol, followed by either a reference of the compile-time constant or a call to a constant constructor.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating Metadata Annotation<\/h2>\n\n\n\n<p>In Dart, we can define our own metadata annotations.<\/p>\n\n\n\n<p>Let&#8217;s understand the following example &#8211;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example &#8211;<\/h3>\n\n\n\n<p>Here&#8217;s an example of defining a @student annotation that takes two arguments &#8211;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-metadata#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-metadata#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-metadata#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>library student;  \nClass Student {  \n     final String studentName;  \n     final String rollno;  \n     const Student(this.studentName, this.code);  \n} <\/code><\/pre>\n\n\n\n<p>And, here is the following example we are using @student annotation.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><a href=\"https:\/\/www.javatpoint.com\/dart-metadata#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-metadata#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/dart-metadata#\"><\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import 'student.dart' ;  \n@Student('studentName', 'rollno')  \nvoid greetHii() {  \n     print(\"Hii Welcome to Javatpoint\");  \n}  <\/code><\/pre>\n\n\n\n<p>In Dart, metadata generally define just before a library name, class, typedef, field, type parameter, factory, function, constructor, parameter, or variable declaration and before an import or export directive. We can retrieve the metadata using reflection in runtime.<\/p>\n\n\n\n<p>Let&#8217;s understand the following example.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example &#8211;<\/h3>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Human{  \n   @Overridden method  \n    void run()  \n   {  \n      print(\"Human is running\");  \n   }  \n}  \nclass Man extends Human{  \n   @Overriding method  \n    void run(){  \n      print(\"Boy is running\");  \n   }  \n}  \nvoid main(){  \n      Man m = new Man();  \n      \/\/This will call the child class version of run()  \n      m.run();  \n}  <\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Boy is running\n<\/code><\/pre>\n\n\n\n<p>In the above code, we have provided the addition information to the both parent class and child class functions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Dart Metadata is used to specify the Dart program with additional information. It usually starts with @ symbol, followed by either a reference of the compile-time constant or a call to a constant constructor. Creating Metadata Annotation In Dart, we can define our own metadata annotations. Let&#8217;s understand the following example &#8211; Example &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[658],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/19819"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=19819"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/19819\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=19819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=19819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=19819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}