From 342a5a4ac9d429e20c7a3e5ee2769b8662d6de6e Mon Sep 17 00:00:00 2001 From: Thomas Hii Date: Sun, 29 Jan 2023 14:54:00 +0000 Subject: [PATCH] Test Annotation --- experiment/container/example1/bin/main.dart | 15 ++++++++++++--- experiment/container/example1/lib/src/models.dart | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 experiment/container/example1/lib/src/models.dart diff --git a/experiment/container/example1/bin/main.dart b/experiment/container/example1/bin/main.dart index 76569588..47ecf359 100644 --- a/experiment/container/example1/bin/main.dart +++ b/experiment/container/example1/bin/main.dart @@ -1,4 +1,5 @@ import 'dart:mirrors'; +import 'package:example1/src/models.dart'; void main() { final stopwatch = Stopwatch()..start(); @@ -14,15 +15,23 @@ void main() { printAnnotationValue(String); printAnnotationValue(Shape); + printAnnotationValue(Square); } class Shape { void draw() => print("Draw Shape"); } +@Person('Will', 'Tom') +class Square { + void greetHii() { + print("Hii Welcome to flutter agency"); + } +} + void printAnnotationValue(final Type clazz) { final DeclarationMirror clazzDeclaration = reflectClass(clazz); - final ClassMirror someAnnotationMirror = reflectClass(Shape); + final ClassMirror someAnnotationMirror = reflectClass(Person); final annotationInstsanceMirror = clazzDeclaration.metadata.where((d) => d.type == someAnnotationMirror); if (annotationInstsanceMirror.isEmpty) { @@ -30,6 +39,6 @@ void printAnnotationValue(final Type clazz) { return; } final someAnnotationInstance = - (annotationInstsanceMirror.first.reflectee as Shape); - print("${someAnnotationInstance.draw}"); + (annotationInstsanceMirror.first.reflectee as Person); + print(someAnnotationInstance.firstName); } diff --git a/experiment/container/example1/lib/src/models.dart b/experiment/container/example1/lib/src/models.dart new file mode 100644 index 00000000..abc1b6d8 --- /dev/null +++ b/experiment/container/example1/lib/src/models.dart @@ -0,0 +1,5 @@ +class Person { + final String firstName; + final String lastName; + const Person(this.firstName, this.lastName); +}