The metadata is to a data that provides information about other data.
Use metadata to give additional information to the caller about your code usage.
How to use metadata?
@deprecated
and @override
.@
You can use the @deprecated
annotation to indicate that this method is deprecated use another one instead.
Using the @deprecated annotation:
class Person {
/// _Deprecated: Use [fullName] instead._
String personName(String firstName, String lastName) {
return '$firstName, $lastName';
}
String fullName(String firstName, String lastName) {
return '$firstName $lastName';
}
}
Why we deprecated the personName method:
,
not appropriate.You can use the @override
annotation to indicate that you are intentionally overriding a method.
class Person {
String fullName(String firstName, String lastName) {
return '$firstName, $lastName';
}
}
class Manager extends Person {
/// _Override: Removes the comma `,` while displaying managers full name
String fullName(String firstName, String lastName) {
return '$firstName $lastName';
}
}
main() {
var person = Person();
print(person.fullName('Rock', 'Star')); // Rock, Star
var manager = Manager();
print(manager.fullName('Rock', 'Star')); // Rock Star
}
In Dart, you can create your own metadata annotations.
library task;
class Task {
final String list;
final String taskName;
const Task(this.list, this.taskName);
}
import 'task.dart';
('Project Name', 'Complete UX/UI design for home screen')
void showTask() {
print('showing task');
}
main() {
showTask();
}